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.
The first line consists of two numbers n and k (1 ≤ n, k ≤ 1010).
If the answer exists then output k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.
6 3
1 2 3
8 2
2 6
5 3
-1
那麼約數m就是數列的最大公約數
#include <bits/stdc++.h>
#define maxn 100005
typedef long long ll;
using namespace std;
bool judge(ll i, ll k) {
if((k+1) <= 2*i/k)
return true;
return false;
}
int main() {
//freopen("in.txt", "r", stdin);
ll n, k, maxs = 0;
scanf("%I64d %I64d", &n, &k);
for(ll i = 1; i * i <= n; i++) {
if(n % i == 0) {
ll m = n / i;
if(judge(m, k))
maxs = max(i, maxs);
if(judge(i, k))
maxs = max(m, maxs);
}
}
if(maxs == 0) {
puts("-1");
return 0;
}
ll cnt = 1;
ll m = n / maxs;
int first = 0;
for(int i = 1; i <= k; i++) {
if(first)
putchar(' ');
if(i != k)
printf("%I64d",cnt * maxs);
else{
cnt--;
printf("%I64d",(m - (1+cnt)*cnt/2) * maxs);
}
cnt++;
first = 1;
}
return 0;
}