time limit per test : 1 second
memory limit per test : 256 megabytes
You are given positive integer number
. You should create such strictly increasing sequence of
positive numbers
, that their sum is equal to
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 .
Input
The first line consists of two numbers
and
.
Output
If the answer exists then output numbers — resulting sequence. Otherwise output . If there are multiple answers, print any of them.
Meaning of the questions:
given
,
, a length construct
increment sequence, and such that the sequence is incremented
and the greatest common divisor of the maximum sequence.
Solution:
First, let's consider, if k is greater than 20w, then it is surely impossible, after all, is the easiest-up sequencing, 2, 3 ...
and then consider enumerate the greatest common divisor. Provided the greatest common factor is c, then we just need to find a sequence of arbitrary n / c sequence to rise, and provided the sequence is s. S and c are obviously factor of n, then only Enumeration enum s or c on the line, the time complexity is
And when you s known, as long as do a rising sequence 1,2,3 ..., k, and give each a plus s / k, and finally the remaining number plus one each from the back It can be.
#include<bits/stdc++.h>
#define LiangJiaJun main
#define ll long long
using namespace std;
ll n,k,a[200004];
ll poa[200004],cnt,delta,rest,sau;
void output(int g,int v){
for(int i=1;i<=k;i++)a[i]=i+delta;
for(int i=k;i>=1&&v>0;i--){
a[i]++;
v--;
}
ll gk=n/sau;
for(int i=1;i<=k;i++){
printf("%lld ",a[i]*gk);
}
puts("");
}
int LiangJiaJun(){
cnt=0;
scanf("%lld%lld",&n,&k);
if(k>2e5||k*(k+1)/2>n)return puts("-1"),0;
sau=k*(k+1)/2;
for(ll i=1;i<=sqrt(n);i++){
if(n%i==0){
poa[++cnt]=i;
if(n!=i*i){
poa[++cnt]=n/i;
}
}
}
sort(poa+1,poa+cnt+1);
int cip=1;
while(cip<=cnt&&poa[cip]<sau)cip++;
if(cip>cnt)return puts("-1"),0;
delta=0;
rest=0;
if(poa[cip]==sau){
output(delta,rest);
}
else{
rest+=poa[cip]-sau;
sau=poa[cip];
delta+=rest/k;
rest%=k;
output(delta,rest);
}
return 0;
}