地址:

题目:

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. 配置Mac漂亮的Shell--Iterm2+OhMyZSH+Agnoster

    安装包管理器 首先当然是解决包管理的问题,Mac下面是Homebrew的天下了 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubuserco ...

  2. sonarqube插件开发(二) 开发插件

    一.环境准备 java 1.8, maven 3.1 检查自己的环境是否支持 sonarqube的插件开发 java -version mvn -version 二.创建maven项目 pom.xml ...

  3. 总结一下最近用到的技术(1)--ultraESB

    最近项目中方法用到了一些新的东西,由于之前没有用到过,现在总结一下,方便以后查阅,本篇文章介绍ultraESB,接下来的文章会介绍JsonSchema,JsonSchamaValidator,Json ...

  4. locate命令的使用

    使用locate命令,遇到了这样的情况:当前目录下有一个文件,而使用这个命令时却查找不到这个文件,上网查了一下,找到了原因,就在下面. 1. find find是最常见和最强大的查找命令,你可以用它找 ...

  5. Laravel 中的异常处理

    这篇文章里,我们将研究 Laravel 框架中最重要也最少被讨论的功能 -- 异常处理. Laravel 自带了一个异常处理类,它能够让你以简单.优雅的方式 report 和 render 异常. 文 ...

  6. Centos7.2安装ruby用于爬虫脚本

    1,系统版本查看 2,安装依赖包 yum -y install ruby-devel yum -y install mysql-devel  yum -y install gcc-c++ gcc  r ...

  7. c++之list的用法

    list同vector一样是c++中的一个模板类.关于它的详细内容可查看c++的文档 http://www.cplusplus.com/reference/list/list/ C++中list的使用 ...

  8. HDU 2829 - Lawrence - [斜率DP]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2829 T. E. Lawrence was a controversial figure during ...

  9. XTU 1264 - Partial Sum - [2017湘潭邀请赛E题(江苏省赛)]

    2017江苏省赛的E题,当时在场上看错了题目没做出来,现在补一下…… 题目链接:http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id ...

  10. 查看mobileprovision信息

    security cms -D -i ***********.mobileprovision