Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) C. Maximum splitting
地址:
题目:
2 seconds
256 megabytes
standard input
standard output
You are given several queries. In the i-th query you are given a single positive integer ni. You are to represent ni as a sum of maximum possible number of composite summands and print this maximum number, or print -1, if there are no such splittings.
An integer greater than 1 is composite, if it is not prime, i.e. if it has positive divisors not equal to 1 and the integer itself.
The first line contains single integer q (1 ≤ q ≤ 105) — the number of queries.
q lines follow. The (i + 1)-th line contains single integer ni (1 ≤ ni ≤ 109) — the i-th query.
For each query print the maximum possible number of summands in a valid splitting to composite summands, or -1, if there are no such splittings.
1
12
3
2
6
8
1
2
3
1
2
3
-1
-1
-1
12 = 4 + 4 + 4 = 4 + 8 = 6 + 6 = 12, but the first splitting has the maximum possible number of summands.
8 = 4 + 4, 6 can't be split into several composite summands.
1, 2, 3 are less than any composite number, so they do not have valid splittings.
思路:
最小合数是4,所以用4去凑就行了
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int main(void)
{
int n,x,ans;cin>>x;
while(x--)
{
scanf("%d",&n);
if(n%==)
ans=n/;
else if(n%==)
{
if(n<)
ans=-;
else if(n==)
ans=;
else
ans=(n-)/+;
}
else if(n%==)
{
if(n<)
ans=-;
else if(n==)
ans=;
else
ans=n/;
}
else
{
if(n<)
ans=-;
else
ans=(n-)/+;
}
printf("%d\n",ans);
}
return ;
}
Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) C. Maximum splitting的更多相关文章
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个 ...
- Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2) D. Something with XOR Queries
地址:http://codeforces.com/contest/872/problem/D 题目: D. Something with XOR Queries time limit per test ...
- Codeforces Round #440 (Div. 1, based on Technocup 2018 Elimination Round 2) C - Points, Lines and Ready-made Titles
C - Points, Lines and Ready-made Titles 把行列看成是图上的点, 一个点(x, y)就相当于x行 向 y列建立一条边, 我们能得出如果一个联通块是一棵树方案数是2 ...
- ACM-ICPC (10/15) Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)
A. Search for Pretty Integers You are given two lists of non-zero digits. Let's call an integer pret ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861C Did you mean...【字符串枚举,暴力】
C. Did you mean... time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861B Which floor?【枚举,暴力】
B. Which floor? time limit per test:1 second memory limit per test:256 megabytes input:standard inpu ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861A k-rounding【暴力】
A. k-rounding time limit per test:1 second memory limit per test:256 megabytes input:standard input ...
- Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)
A. k-rounding 题目意思:给两个数n和m,现在让你输出一个数ans,ans是n倍数且末尾要有m个0; 题目思路:我们知道一个数末尾0的个数和其质因数中2的数量和5的数量的最小值有关系,所以 ...
- 【模拟】 Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) C. Tests Renumeration
题意:有一堆数据,某些是样例数据(假设X个),某些是大数据(假设Y个),但这些数据文件的命名非常混乱.要你给它们一个一个地重命名,保证任意时刻没有重名文件的前提之下,使得样例数据命名为1~X,大数据命 ...
随机推荐
- 提取ipa里面的资源图片
有时候发现个不错的UI,就想扒出来看看,ipa里的图片你知道的,都不能直接用,所以找到两个方法:一.用python转换1.将ipa文件后缀改为zip,然后解压缩.2.新建一个文件夹,将解压后的包里的p ...
- Docker学习计划三:Dockerfile 使用
我们使用 Dockerfile 定义镜像,依赖镜像来运行容器,因此 Dockerfile 是镜像和容器的关键,Dockerfile 可以非常容易的定义镜像内容 首先通过一张图来了解 Docker 镜像 ...
- redis集群节点宕机
redis集群是有很多个redis一起工作,那么就需要这个集群不是那么容易挂掉,所以呢,理论上就应该给集群中的每个节点至少一个备用的redis服务.这个备用的redis称为从节点(slave). 1. ...
- ububtu下安装配置搜狗输入法
安装搜狗输入法 for linux参考教程: http://blog.csdn.net/u013894834/article/details/60357071 安装后会遇到无法切换英文的问题,可以参考 ...
- TACOTRON:端到端的语音合成
tacotron主要是将文本转化为语音,采用的结构为基于encoder-decoder的Seq2Seq的结构.其中还引入了注意机制(attention mechanism).在对模型的结构进行介绍之前 ...
- 0004python中的map,reduce,lambda,filter
编程实现:a[0]*b[0] + a[1]*b[1] +...+a[i]*b[j] >>> a=[1,2,3,4,5]>>> b=[6,7,8,9,0] >& ...
- hadoop 2.x HA(QJM)安装部署规划
一.主机服务规划: db01 db02 ...
- LoadRunner-关联相关(解决方法二)
用例为:添加通知,下发给用户. 录制好脚本,replay时脚本未报错,但实际登录网页操作未完成(只添加了通知,未下发给用户). LR自动关联没有内容,手动查看服务器response,在保存时有一个id ...
- Python开发【模块】:Weakref
Weak references 前言: weakref模块允许python开发者创建弱引用对象. 再接下来中,术语referent代表被弱引用所引用的对象. 一个弱引用对于对象是不能够保持对象存活的: ...
- paas平台
paas平台 定义:PaaS是云计算中重要的一类服务,为用户提供应用的全生命周期管理和相关的资源服务.通过PaaS,用户可以完成应用的构建.部署.运维管理,而不需要自己去搭建计算环境,如安装服务器.操 ...