Solution to a problem [CF803C] Maximal GCD

Face questions

Resolve

Started to think that this question difficult ...

In fact, as long as the set \ (D \) of \ (A \) is the greatest common factor,

Immediate \ (A [I] = S [I] * D \) ,

因为\(n=\sum_{i=1}^{n}a[i]=\sum_{i=1}^ns[i]*d=d*\sum_{i=1}^ns[i]\).

So \ (D \) must be \ (n-\) divisors,

Therefore descending enumeration \ (d \) ,

Determining whether the configuration \ (K \) a \ (s [i] \) on the line.

Judgment is very simple,

As long \ (\ sum_. 1} ^ {Ki = I = (K +. 1) * K / 2 <= n-/ D \) ,

Then \ (S [I. 1 = \) ~ \ (. 1-K] I = \) , \ (S [K] \) is equal to the remaining like.

(A bit shabby but should be good to think about it ...)

Finally, note that \ (k \) is greater than approximately \ (200,000 \) when direct impossible.

Otherwise it will take burst \ (long long \) oflzf marching next to the T stop.

~~ ** forgotten today forced to sort results ignorant of the ~ ~ WA

code:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long
#define fre(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
using namespace std;

inline int read(){
    int sum=0,f=1;char ch=getchar();
    while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
    return f*sum;
}

const int N=200000;
int n,K;
int sta[N],top=0;

signed main(){
    n=read();K=read();
    if(K>=N){puts("-1");return 0;}
    if((K*(K+1)/2)>n){puts("-1");return 0;}
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            sta[++top]=i;
            if(i*i!=n) sta[++top]=n/i;
        }
    }
    sort(sta+1,sta+top+1);
    for(int i=top;i>=1;i--){
        int d=sta[i];
        int s=n/d;
        if((K*(K+1)/2)<=s){
            for(int j=1;j<K;j++) printf("%lld ",j*d),s-=j;
            printf("%lld\n",s*d);
            return 0;
        }
    }
    puts("-1");
    return 0;
}

Guess you like

Origin www.cnblogs.com/zsq259/p/11512294.html