题解 [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 ...
随机推荐
- Oracle存储过程——日常记录
代码规范 Oracle存储过程,关键字大写,变量小写并以v_开头,规范代码,提高可读性 赋值与判断符号 Oracle存储过程,变量赋值使用 := 符号,条件判断直接用 = 符号. 变量声明需在 beg ...
- 【转载】在一台电脑上运行两个或两个以上的tomcat
作者注: 本片为转载文章,一台电脑运行两个及以上tomcat的原因是:第一个eclipse版本是4.5,最高支持tomcat8.0版本,并且这个版本的eclipse通过svn提交和更新项目极其缓慢,无 ...
- C#UDP异步通信
using SetingDemo.LogHelp;using SetingDemo.SingleRowDeclare;using System;using System.Collections.Gen ...
- luogu2568GCD题解--欧拉函数
题目链接 https://www.luogu.org/problemnew/show/P2568 分析 题目即求\(\sum_{i=1}^N \sum_{j=1}^N [gcd(i,j)\) \(is ...
- Django rest-framework框架-请求数据校验
验证实例: class UserInfoSerializer(serializers.Serializer): title = serializer.CharField(error_messages= ...
- Linux学习(二)-Xshell 5和Xftp 5的安装和使用
(一)软件介绍: (1)Xshell: Xshell通过互联网可以连接到远程的服务器,然后通过模拟终端来实现对服务器的各种操作,而且这款软件可以很好的解决中文乱码问题,非常的方便快捷. (2)Xftp ...
- 嵌入式安装telnet
busybox配置 Defined at networking/Config.in:784 Depends on: TELNET Location: -> Networking Utilitie ...
- Redis和MemCache静态Map做缓存区别
本地缓存和分布式缓存 本地缓存:使用自带的map或者guava实现的是本地缓存,最主要的特点是轻量以及快速,生命周期随着jvm的销毁而结束,并且在多实例的情况下,每个实例都需要各自保存一份缓存,缓存不 ...
- Yii 2.0 GII 访问404错误
网上大部分都是普通的开启和配置资料 按照网上资料配置 访问localhost/index/php?r=gii 总是提示404错误 解决方法如下: Yii基础版中的 web.php 代码如下 if (Y ...
- impala 建表时报错,不支持中文
1.错误信息 (1366, "Incorrect string value: '\\xE6\\x8E\\x88\\xE6\\x9D\\x83...' for column 'search' ...