题面

解析

一开始以为这题很难的...

其实只要设\(d\)为\(a\)的最大公因数,

即\(a[i]=s[i]*d\),

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

所以\(d\)一定是\(n\)的约数,

因此从大到小枚举\(d\),

判断能否构造\(k\)个\(s[i]\)就行了.

判断也很简单,

只要\(\sum_{i=1}^ki=(k+1)*k/2<=n/d\),

然后将\(s[i=1\)~\(k-1]=i\),\(s[k]\)等于剩下的就好了.

(有点简陋但应该很好想吧...)

最后注意\(k\)大约大于\(200000\)时就直接不可能了.

要不然乘起来会爆\(long long\)的旁边的lzf大仙T个不停.

今天**地忘记排序结果懵逼地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;
}

题解 [CF803C] Maximal GCD的更多相关文章

  1. codeforces 803C Maximal GCD(GCD数学)

    Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...

  2. Maximal GCD CodeForces - 803C (数论+思维优化)

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

  3. Codeforces 803C. Maximal GCD 二分

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

  4. AC日记——Maximal GCD codeforces 803c

    803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...

  5. Educational Codeforces Round 20 C. Maximal GCD

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

  6. Codeforces H. Maximal GCD(贪心)

    题目描述: H. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. CodeForce-803C Maximal GCD(贪心数学)

    Maximal GCD CodeForces - 803C 现在给定一个正整数 n.你需要找到 k 个严格递增的正整数 a1, a2, ..., ak,满足他们的和等于 n 并且他们的最大公因数尽量大 ...

  8. 「CF803C」 Maximal GCD

    题目链接 戳我 \(Solution\) 令\(gcd\)为\(x\),那么我们将整个序列\(/x\),则序列的和就变成了\(\frac{n}{x}\),所以\(x\)必定为\(n\)的约数所以现在就 ...

  9. 【CodeForces 803 C】Maximal GCD(GCD+思维)

    You are given positive integer number n. You should create such strictly increasingsequence of k pos ...

随机推荐

  1. 【AtCoder】AGC002

    AGC002 A - Range Product #include <bits/stdc++.h> #define fi first #define se second #define p ...

  2. ffmpeg解码音视频过程(附代码)

    0. 引言 最近一直在使用和学习ffmpeg. 工作中需要拉流解码, 获取音频和视频数据. 这些都是使用ffmpeg处理. 因为对ffmpeg接触不多, 用的不深, 在使用的过程中经常遇到不太懂的地方 ...

  3. B - How many integers can you find

      Now you get a number N, and a M-integers set, you should find out how many integers which are smal ...

  4. 使用jenkins 构建时,字体图标报错的问题。

    最近一个项目开发中,我们在本地进行项目打包时,可以正常打包. 但是在使用jenkins构建时,一直报错,提示无法加载字体文件.can't resolve module '....xxxx.TTF ' ...

  5. 牛客 26E 珂学送分2 (状压dp)

    珂...珂...珂朵莉给你出了一道送分题: 给你一个长为n的序列{vi},和一个数a,你可以从里面选出最多m个数 一个合法的选择的分数定义为选中的这些数的和加上额外规则的加分: 有b个额外的规则,第i ...

  6. nginx反向代理服务器以及负载均衡,从安装到配置

    nginx的具体作用不用细说,很强大,做负载均衡.反向代理服务器解决前端跨域问题等等.下面是nginx的安装过程 首先nginx主要的依赖: pcre. pcre-devel zlib zlib-de ...

  7. php 处理数字为金钱格式

    number_format(需要转换的数字,保留小数个数,小数点符号,每三位的分隔符) echo number_format("1000000")."<br> ...

  8. element-ui当中table组件的合并行和列的属性:span-method的用法

    背景 最近基本上都是以Vue来构建项目,而UI框架也基本上都是使用的element-ui,所以里面组件用的也是越来越多,今天想记录的是非常非常小的一个属性的用法. Table组件 Table组件用了真 ...

  9. POJ 1789 Prim

    给定N个字符串,某个字符串转为另一个字符串的花费为他们每一位不相同的字符数. 求最小花费Q. Input 多组输入,以0结束. 保证N不超过2000. Output 每组输出"The hig ...

  10. VisualVM的使用

    1.解压压缩包(如visualvm143.zip) 2.修改etc/visualvm.conf 中的visualvm_jdkhome配置 3.双击bin/visualvm.exe 4.安装插件,可能一 ...