Description:

You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a 1 , a 2 , . . . , a k a_{1} , a_{2}, ..., a_{k} 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 1 0 10 ) k (1 ≤ n, k ≤ 10^{10}) k(1n,k1010) .

Output:

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

Sample Input:

6 3

Sample Output:

1 2 3

Sample Input:

8 2

Sample Output:

2 6

Sample Input:

5 3

Sample Output:

-1

题目连接

遍历公约数,检查是否“strictly increasing”。
数据会爆long long,注意特判。

AC代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5+5;
const double eps = 1e-5;
const double pi = asin(1.0)*2;
const double e = 2.718281828459;

ll n, k;
ll d;
ll judge;
ll sum;
ll sqr;

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    d = -1;
    scanf("%lld%lld", &n, &k);
    if (k > 141420) {
        printf("-1");
        return 0;
    }
    judge = k * (k + 1) / 2;
    sum = k * (k - 1) / 2;
    sqr = sqrt(n);
    for (int i = 1; i <= sqr; ++i) {
        if (n % i) {
            continue;
        }
        if (i >= judge) {
            d = n / i;
            break;
        }
        if (n - i * sum > (k - 1) * i) {
            d = i;
        }
    }
    if (d == -1) {
        printf("-1");
    }
    else {
        for (int i = 1; i < k; ++i) {
            printf("%lld ", i * d);
        }
        printf("%lld", n - d * k * (k - 1) / 2);
    }
   return 0;
}