题面

解析

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

其实只要设\(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. servlet获取checkbox的值出现选中的值为on。问题所在。。。

    <form action="/Http/request06" method="post"> 用户名:<input type="tex ...

  2. Redis 学习笔记(篇八):事件

    Redis 服务器是一个事件驱动程序,服务器需要处理以下两类事件: 文件事件: Redis 服务器通过套接字与客户端(或者其他 Redis 服务器)进行连接,而文件事件就是服务器对套接字操作的抽象.服 ...

  3. Simple Library Management System HDU - 1497(图书管理系统)

    Problem Description After AC all the hardest problems in the world , the ACboy 8006 now has nothing ...

  4. python+selenium+webdriver+BeautifulSoup实现自动登录

    from selenium import webdriverimport timefrom bs4 import BeautifulSoupfrom urllib import requestimpo ...

  5. windows服务与log4net应用

    有时候我们需要用到window服务来执行定时任务,然后配合log4net记录程序运行情况,这里简单记录下配置的整个过程以及注意要点: 一.添加windows服务 1.设计页面,右键添加安装程序

  6. 梯度直方图(HOG,Histogram of Gradient)

    1.介绍 HOG(Histogram of Oriented Gradient)是2005年CVPR会议上,法国国家计算机科学及自动控制研究所的Dalal等人提出的一种解决人体目标检测的图像描述子,该 ...

  7. JSON在JS中的应用

    一. JSON在JS中的应用: 首先解释下JSON对象与普通js对象字面量定义时格式的区别: Js对象字面量定义格式: var person = { name:"Wede", ag ...

  8. Linux更新程序脚本

    DATE=$(date +%Y%m%d_%H%M%S) cd /opt/anystreaming/transcoder/ mv dll/libmonitor_service.so "dll/ ...

  9. Spring切面编程Aspect之@Before和@Around用法

    查看dao层使用的sql import java.util.Arrays; import org.apache.commons.lang.ArrayUtils; import org.aspectj. ...

  10. JavaScript02

    一. 判断// 三元表达式// 循环// 判断: 用的最多的就是if判断// 1.// if(条件){// 当条件满足以后执行的语句// } // 2.// if(条件){// // }else{// ...