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,大数据命 ...
随机推荐
- Metrics.Net构建指标监控中心
Metrics.NET(https://github.com/etishor/Metrics.NET)是一个给CLR 提供度量工具的包,它是移植自Java的metrics,支持的平台 .NET 4.5 ...
- listctrl查找定位 使用测试过还很好用
35.listctrl查找定位 使用测试过还很好用 // 简单的查找函数// FindString(CListCtrl& , 查找内容 , 开始位置 , 到达底部时是否从头查找) int F ...
- ArcEngine TextElement 定位点的问题
做ArcGIS Add-In开发,需要在ArcMap中数据视图的左上角加一个上标,如果上标与数据中的地名图层重合,则放在右上角. 上标通过ITextElement,IElement,ITextSymb ...
- MySQLCouldn't find MySQL manager
mysql出现MySQLCouldn't find MySQL manager错误的解决办法 最近我的一个linux服务器上的网站全部无法打开.....访问网站没有提示.....只出现该页无法显示的错 ...
- 微信小程序APP(商超营销类)经验总结
项目介绍 这是一款主打门店营销的小程序.包括首页.门店.营销.个人设置.登录.数据统计展示.营销设置等. 本来要独立完成整个项目,包括前后端一套的,有些意外因素,项目临时收尾(说明:只完成了前端的部分 ...
- POJ-1926 Pollution
Pollution Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4049 Accepted: 1076 Description ...
- 2.5BatchNormalzation
BatchNormalzation是一种解决深度神经网络层数太多,而没有办法有效前向传递的问题,因为每层的输出值都会有不同的均值和方差,所以输出数据的分布也不一样. 如果对于输入的X*W本身得到的值通 ...
- Ubuntu 14.04 使用速度极快的Genymotion 取代蜗牛速度的原生AVD模拟器
Ubuntu 14.04 使用速度极快的Genymotion 取代蜗牛速度的原生AVD模拟器 2014-5-29阅读4045 评论0 默认的AVD的速度可谓奇慢无比,一番搜索最后找到了 ...
- 迷宫问题---poj3984(bfs,输出路径问题)
题目链接 主要就是输出路径问题: pre[x][y]表示到达(x,y)是由点(pre[x][y].x, pre[x][y].y)而来: #include<stdio.h> #includ ...
- Number Sequence--POJ1019
Number Sequence Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 35251 Accepted: 10151 ...