Codeforces Round #240 (Div. 2) Mashmokh and Numbers
来源:互联网 发布:2017淘宝发布宝贝教程 编辑:程序博客网 时间:2024/06/05 00:20
题意找出一组数列,满足每相邻的两个数的最大公因数和为给定的值。,注意相邻两个数的公约数为一就好做了,注意下边界即可
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.
#include <stdio.h>int main(){ int n,k; while(scanf("%d %d",&n,&k)==2) { if(n==1&&k!=0) printf("-1\n"); else if(n==1&&k==0) printf("1\n"); else if(n/2>k) printf("-1\n"); else { int a=1,b=2; int t=n/2; t*=2; int x=n/2; int last=k-(x-1); for(int i=1;i<x;i++) { if(i==1) { while(a==last||b==last||a==2*last||b==2*last)a+=2,b+=2; printf("%d %d",a,b); } else { while(a==last||b==last||a==2*last||b==2*last)a+=2,b+=2; printf(" %d %d",a,b); } a+=2,b+=2; } if(n==2)printf("%d %d",last,2*last); else printf(" %d %d",last,2*last); if(n&1)printf(" 1000000000"); printf("\n"); } } return 0;}
- Codeforces Round #240 (Div. 2) C. Mashmokh and Numbers
- Codeforces Round #240 (Div. 2) Mashmokh and Numbers
- Codeforces Round #240 (Div. 2) A. Mashmokh and Lights
- Codeforces Round #240 (Div. 2)B. Mashmokh and Tokens
- Codeforces Round #240 (Div. 2) D. Mashmokh and ACM
- Codeforces Round #240 (Div. 1)---B.Mashmokh and ACM(dp)
- codeforces#240_div2_C Mashmokh and Numbers
- Mashmokh and ACM(Codeforces Round #240)
- Codeforces Round #240 (Div. 1)B---Mashmokh and ACM(水dp)
- Codeforces Round #226 (Div. 2) C. Bear and Prime Numbers
- Codeforces Round #232 (Div. 2) B. On Corruption and Numbers
- Codeforces Round #235 (Div. 2) ----D. Roman and Numbers
- Codeforces Round #226 (Div. 2)C. Bear and Prime Numbers
- Codeforces Round #136 (Div. 2) B. Little Elephant and Numbers
- Codeforces Round #235 (Div. 2) D. Roman and Numbers
- Codeforces Round #160 (Div. 2)---A. Roma and Lucky Numbers
- Codeforces Round #226 (Div. 2)--C. Bear and Prime Numbers
- Codeforces Round #358 (Div. 2) A. Alyona and Numbers
- Leetcode: ZigZag Conversion
- 第五周作业——有向图邻接表表示及反向图构造
- hdu 4565 So Easy!(矩阵快速幂)
- jquery获取复选框的值
- String in C sharp
- Codeforces Round #240 (Div. 2) Mashmokh and Numbers
- 北邮新OJ93
- CWE-252: 未检查的返回值(Unchecked Return Value)
- ExecuteReader(),ExecuteNonQuery(),ExecuteScalar(),ExecuteXmlReader()之间的区别
- poj2411(状压dp)
- LeetCode || Two Sum
- 使用DbgHelp获取函数调用堆栈之inline assembly(内联汇编)法
- U盘安装CentOS6.4
- 2014-4-9晚JUULUU开源软件官网挂了!!!