Educational Codeforces Round 20 C. Maximal GCD

1.题目链接

http://codeforces.com/contest/803/problem/C

2.题面

C. Maximal GCD
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal.

Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.

If there is no possible sequence then output -1.

Input

The first line consists of two numbers n and k (1 ≤ n, k ≤ 1010).

Output

If the answer exists then output k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.

Examples
input
Copy
6 3

output
Copy
1 2 3

input
Copy
8 2

output
Copy
2 6

input
Copy
5 3

output
Copy
-1

5.代码实现

#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 2005;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=2.718281828459045235360287471352662;
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
ll n,k,flag;
vector<ll> v;
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
cin>>n>>k;
if(k>1000000)
{
cout<<-1<<endl;
return 0;
}
ll pp=((1+k)*k)/2;
if(n<pp)
{
cout<<-1<<endl;
return 0;
}
for(ll i=1;i*i<=n;i++)
{
if(n%i==0)
{
v.pb(i);
v.pb(n/i);
}
}
int cnt=v.size();
sort(v.begin(),v.end());
for(int i=cnt-1;i>=0;i--)
{
if(n/v[i]>=pp)
{
for(ll j=1;j<=k-1;j++)
printf("%lld ",j*v[i]);
printf("%lld ",(n/v[i]-(k*(k-1))/2)*v[i]);
return 0;
}
}
cout<<-1<<endl;
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}


6.反思

• 本文已收录于以下专栏：

举报原因： 您举报文章：Educational Codeforces Round 20 C. Maximal GCD 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)