CF---C. Mashmokh and Numbers
来源:互联网 发布:淘宝跳失率怎么算 编辑:程序博客网 时间:2024/05/16 01:55
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and y from the board, he gets gcd(x, y) points. At the beginning of the game Bimokh has zero points.
Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way.
Please, help him. Find n distinct integers a1, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.
The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).
If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
5 2
1 2 3 4 5
5 3
2 4 3 7 1
7 2
-1
gcd(x, y) is greatest common divisor of x and y.
//这道题目WA了很多次,一开始思路是对的,还是需要从题目中寻找好的突破口, 这里k的取值范围比较特殊,不到10^9,而是10^8.
突破口就在这里! 但是后来注释那里分类有点错误,WA了很多次,这里做一总结,还是不够细心。
Code:
#include <stdio.h>#include <math.h>#include <string.h>#include <algorithm>#include <iomanip>#include <iostream>using namespace std; const int N=100000001; int main(){ freopen("in.txt","r",stdin); int i,j,k,n,m, a,b; while(scanf("%d %d",&n,&m)!=EOF){ if(n==1 && m!=0) printf("-1\n"); else{ if(n/2 > m) printf("-1\n"); else if(n/2 == m){ printf("1"); for(i=2;i<=n;i++) printf(" %d",i); printf("\n"); } else{ int t=n/2; k=m-t+1; int kk=N%k; kk=k-kk; printf("%d %d",k,N+kk); m=n-2; k=100001; //这里一开始枚举的位置出错了,导致出现了重复! while(m--){ printf(" %d",k); k++; } printf("\n"); } } } return 0;}
- CF---C. Mashmokh and Numbers
- A. Mashmokh and Numbers
- A. Mashmokh and Numbers
- CF 414C Mashmokh and Reverse Operation(分治)
- cf 240 Mashmokh and ACM
- cf,A. Mashmokh and Lights
- Codeforces Round #240 (Div. 2) C. Mashmokh and Numbers
- CF B. Mashmokh and ACM dp
- cf——A. Mashmokh and Lights
- cf——B. Mashmokh and Tokens
- CF 240 D. Mashmokh and ACM
- CF 414B Mashmokh and ACM
- codeforces#240_div2_C Mashmokh and Numbers
- Codeforces 414A Mashmokh and Numbers(构造)
- CodeForces 414A Mashmokh and Numbers
- CodeForces 414A Mashmokh and Numbers
- CodeForces 414 C. Mashmokh and Reverse Operation
- CF:Problem 385C - Bear and Prime Numbers 预处理DP
- Js学习---妙味课堂2-1
- Js学习---妙味课堂2-2 (说一些DOM的基础知识)
- Js学习---妙味课堂2-3 (BOM基础)
- New Linux2.6 I2C Driver Model Example
- Js学习---妙味课堂3-1 (事件对象和事件冒泡)--- 获取鼠标+键盘事件
- CF---C. Mashmokh and Numbers
- CF---C. Unusual Product
- 算法竞赛入门经典---函数部分4(动态规划)
- 2014.4.10 Web主机服务器建立
- 背景颜色渐变 css3 ---- 转自:至尊宝的BLOG http://blog.sina.com.cn/zzbnie
- 妙味课堂:css学习--- 制作一个网页html+css过程
- Web --- 课堂Js学习总结 --- 14年4月22日
- Notepad++ 配置
- 正则表达式