CodeForce 414 A Mashmokh and Numbers
2705 ワード
リンク:http://codeforces.com/problemset/problem/414/A
Mashmokh and Numbers
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
out put:standard output
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.The n Bimokh makes several moves.On the second the the second the the the secondand 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 begining of the game Bikhame.Bizers
Mashmokh wants to win t he game.For t his reason he wants boss to get exactly k points in total.But the gy doesn't know chose the initial sequence in the right way.
Please,help him.Find n distinct integers a 1,̵a2,̵…,_;ansuch that his boss will score exactly k points.Also Mashmokh can't memorize tohumbers.Themberse fore 109.The of。
Input
The first line of input contains two space-separated integers n,̵k (1̵≦̵n≦105; 0̵≦̵k≦108).
Output
If such sequence doesn't exist output-1 others wise output n distinct space-separated integers a 1,̵a 2,an… (1̵≦̵ai≦109).
Sample test(s)
Input
gcd(x,̵y)is greatest common divisor of x and y.
ACコードを直接添付します。
Mashmokh and Numbers
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
out put:standard output
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.The n Bimokh makes several moves.On the second the the second the the the secondand 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 begining of the game Bikhame.Bizers
Mashmokh wants to win t he game.For t his reason he wants boss to get exactly k points in total.But the gy doesn't know chose the initial sequence in the right way.
Please,help him.Find n distinct integers a 1,̵a2,̵…,_;ansuch that his boss will score exactly k points.Also Mashmokh can't memorize tohumbers.Themberse fore 109.The of。
Input
The first line of input contains two space-separated integers n,̵k (1̵≦̵n≦105; 0̵≦̵k≦108).
Output
If such sequence doesn't exist output-1 others wise output n distinct space-separated integers a 1,̵a 2,an… (1̵≦̵ai≦109).
Sample test(s)
Input
5 2
Output1 2 3 4 5
Input5 3
Output2 4 3 7 1
Input7 2
Output-1
ノートgcd(x,̵y)is greatest common divisor of x and y.
ACコードを直接添付します。
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <iomanip>
#include <ctime>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
//#pragma comment(linker, "/STACK:102400000, 102400000")
using namespace std;
typedef unsigned int li;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double pi = acos(-1.0);
const double e = exp(1.0);
const double eps = 1e-8;
int n, k;
int main()
{
ios::sync_with_stdio(false);
while (~scanf("%d%d", &n, &k))
{
int cnt = n>>1;
if (cnt>k || (cnt==0&&k!=0))
printf("-1
");
else if (cnt==0 && k==0)
printf("1
");
else
{
int i, extra=k-cnt+1;
printf("%d %d", extra, 2*extra);
for (i=2*extra+1; --cnt; i+=2)
printf(" %d %d", i, i+1);
if (n & 1)
printf(" %d", i);
printf("
");
}
}
return 0;
}