题目链接:Codeforces 414A Mashmokh and Numbers
题目大意:给出n和k,表示说在一个长度为n的序列中,每次从头取走了个数,得分为两个数的gcd,问说最后得分刚好为k的序列是否存在,给出序列,不存在输出-1.
解题思路:除了第一对以外,其他的得分均为1,然后第一对的得分为k - 后面得的分数。n为1的时候特殊考虑。
#include <stdio.h>
#include <string.h>
int main () {
int n, k;
scanf("%d%d", &n, &k);
if (n == 1) {
if (k == 0)
printf("1\n");
else
printf("-1\n");
} else if (n/2 > k) {
printf("-1\n");
} else {
int x = k - (n - 2) / 2;
printf("%d %d", x, x * 2);
x = x * 2 + 1;
for (int i = 2;i < n; i++)
printf(" %d", x++);
printf("\n");
}
return 0;
}