题解 [CF803C] Maximal GCD
解析
一开始以为这题很难的...
其实只要设\(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的更多相关文章
- codeforces 803C Maximal GCD(GCD数学)
Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...
- Maximal GCD CodeForces - 803C (数论+思维优化)
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces 803C. Maximal GCD 二分
C. Maximal GCD time limit per test: 1 second memory limit per test: 256 megabytes input: standard in ...
- AC日记——Maximal GCD codeforces 803c
803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...
- 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 ...
- Codeforces H. Maximal GCD(贪心)
题目描述: H. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeForce-803C Maximal GCD(贪心数学)
Maximal GCD CodeForces - 803C 现在给定一个正整数 n.你需要找到 k 个严格递增的正整数 a1, a2, ..., ak,满足他们的和等于 n 并且他们的最大公因数尽量大 ...
- 「CF803C」 Maximal GCD
题目链接 戳我 \(Solution\) 令\(gcd\)为\(x\),那么我们将整个序列\(/x\),则序列的和就变成了\(\frac{n}{x}\),所以\(x\)必定为\(n\)的约数所以现在就 ...
- 【CodeForces 803 C】Maximal GCD(GCD+思维)
You are given positive integer number n. You should create such strictly increasingsequence of k pos ...
随机推荐
- 【AtCoder】AGC033(A-F)
AGC033 A - Darker and Darker 直接BFS #include <bits/stdc++.h> #define fi first #define se second ...
- taglib block
新建文件 package com.augmentum.oes.taglib; import javax.servlet.jsp.JspException; import javax.servlet.j ...
- Linux weblogic启停
一般weblogic启停在windows下很方便使用图标方式.但是在linux下需要杀掉weblogic进程才能真正关掉weblogic. 1.查询weblogic进程 ps -ef | grep & ...
- ArrayList插入1000w条数据的时间比较分析
一分钟系列: 读懂GC日志 ArrayList插入1000w条数据之后,我怀疑了jvm... Java JIT性能调优 Java性能优化指南系列(三):理解JIT编译器 准备:调试程序加入VM Opt ...
- Java 并发进阶常见面试题总结
声明:本文内容完全来自网络,转自GitHub->JavaGuide(https://github.com/Snailclimb/JavaGuide),致谢 1. synchronize ...
- -bash: /usr/librxec/grepconf.sh:Nosuch file or directory
最近修改/etc/profile文件时,不小心在后面添加了source /etc/profile,导致使用xshell登录远程linux的时候出现下面的信息, 一直无法进入linux,将profile ...
- 开始学Python 啦 ,持续不断总结中。。(转)快捷键的使用
最重要的快捷键1. ctrl+shift+A:万能命令行2. shift两次:查看资源文件新建工程第一步操作1. module设置把空包分层去掉,compact empty middle packag ...
- vue项目中导出PDF的两种方式
参考大家导出的方式,基本上是如下两种: 1.使用 html2Canvas + jsPDF 导出PDF, 这种方式什么都好,就是下载的pdf太模糊了.对要求好的pdf这种方式真是不行啊! 2.调用浏览器 ...
- 网易云音乐ncm加密格式批量转换为flac,mp3
从网易云下载的某些付费歌曲下载下来会是ncm格式.ncm是个啥?就是你下完一首歌被网易云加密成它自己独有的ncm格式,这个ncm不能在其他播放器播放,如果网易云你会员到期了同样也会提示你无法播放(不是 ...
- js中的函数提升和变量提升
变量提升和函数提升: 就是将变量声明或者函数全部代码提升到当前作用域(全局作用域或函数作用域)最开始的部分. JavaScript中函数域为最小域范围:for循环.while循环.if语句.switc ...