地址:

题目:

C. Maximum splitting
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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.

Examples
input
1
12
output
3
input
2
6
8
output
1
2
input
3
1
2
3
output
-1
-1
-1
Note

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的更多相关文章

  1. Codeforces Round #440 (Div. 2, based on Technocup 2018 Elimination Round 2)

    A. Search for Pretty Integers 题目链接:http://codeforces.com/contest/872/problem/A 题目意思:题目很简单,找到一个数,组成这个 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. 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的数量的最小值有关系,所以 ...

  9. 【模拟】 Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) C. Tests Renumeration

    题意:有一堆数据,某些是样例数据(假设X个),某些是大数据(假设Y个),但这些数据文件的命名非常混乱.要你给它们一个一个地重命名,保证任意时刻没有重名文件的前提之下,使得样例数据命名为1~X,大数据命 ...

随机推荐

  1. EF---延迟加载技术

    延迟加载: 优点:只在需要的时候加载数据,不需要预先计划,避免了各种复杂的外连接.索引.视图操作带来的低效率问题 使用方式:两步 第一:在需要延迟加载的属性前加上virtual ,该属性的类型可以是任 ...

  2. 【读书笔记】setsockopt

    setsockopt   设置套接口的选项. #include <sys/types.h> #include <sys/socket.h> int setsockopt(int ...

  3. 在python pydev中使用todo标注任务

    在做自动化测试时,有部分代码因需求未定或界面需要更改,代码不做修改或更新,这里就需要用到TODO功能. 在PyCharm中TODO功能很详细,但在pydev中怎么用呢.看了文档后,截图如下: 1.设置 ...

  4. tomcat如何配置启动时自动部署webapps下的war包

    1.找到 tomcat安装目录/conf/server.xml 2.修改host元素的配置如下: <Host name="localhost" appBase="w ...

  5. C语言中的数组的使用——混乱的内存管理

    在C语言中想要创建数组只能自己malloc或者calloc,数组复制则是memcpy. 这样创建出来的数组在调用时是不会检测数组边界的,即你声明了一个长度为5的数组,却可以访问第6个位置……也可以给第 ...

  6. adviser vs mentor

    研究生或博士生提到自己导师的时候是说adviser呢?还是mentor呢? 至少我认识一个Berkeley的博士是说adviser的. 另外,我的导师也是说adviser. 那还是说adviser吧- ...

  7. 兵器簿之cocoaPods的安装和使用

    以前添加第三方库的时候总是直接去Github下载然后引入,但是如果这些第三方库发生了更新,我们还需要手动去更新项目,所以现在引入之前一直想弄都一直没有弄的cocoaPods,现在演示一把过程 其实非常 ...

  8. powerdesigner唯一约束设置

    双击unique_pos_code

  9. DISTINCT 与 GROUP BY 的比较

    看了很多文章,这两个SQL语句在不同的数据库上面的实现上可能有相同或有不同,但是应当要明确它们在功能概念上的区别,最终得出结论: GROUP BY 用来使用聚集函数获得值,比如 AVG, MAX, M ...

  10. HOJ 1444 Humble Numbers

    Humble Numbers My Tags (Edit) Source : University of Ulm Internal Contest 1996 Time limit : 1 sec Me ...