CodeFoorces 803C Maximal GCD
枚举。
枚举$gcd$,然后计算剩下的那个数能不能分成$k$个递增的数。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std; long long b[100010];
long long ans[200010];
int sz;
long long n,k; void init()
{
for(long long i=1;i*i<=n;i++)
{
if(n%i!=0) continue;
b[sz++] =i;
if(i!=n/i) b[sz++] =n/i;
}
} int main()
{
scanf("%lld%lld",&n,&k);
init(); sort(b,b+sz); if(k>200000)
{
printf("-1\n");
return 0;
} int suc=0;
for(int i=sz-1;i>=0;i--)
{
long long sum = n/b[i];
long long p = (1+k)*k/2;
if(p>sum) continue; for(int j=1;j<=k;j++)
{
ans[j] = j;
sum = sum-ans[j];
}
ans[k]+=sum; for(int j=1;j<=k;j++)
{
ans[j]=ans[j]*b[i];
} suc=1;
break;
} if(suc==0)
{
printf("-1\n");
}
else
{
for(long long i=1;i<=k;i++)
{
printf("%lld",ans[i]);
if(i<k) printf(" ");
else printf("\n");
}
} return 0;
}
CodeFoorces 803C Maximal GCD的更多相关文章
- codeforces 803C Maximal GCD(GCD数学)
Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...
- Codeforces 803C. Maximal GCD 二分
C. Maximal GCD time limit per test: 1 second memory limit per test: 256 megabytes input: standard in ...
- CodeForces - 803C Maximal GCD 【构造】
You are given positive integer number n. You should create such strictly increasing sequence of k po ...
- Codeforces 803C. Maximal GCD
题目链接:http://codeforces.com/contest/803/problem/C 中了若干trick之后才过... k个数的严格递增序列最小权值和就是${n*(n+1)/2}$,枚举这 ...
- AC日记——Maximal GCD codeforces 803c
803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...
- Maximal GCD CodeForces - 803C (数论+思维优化)
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- CodeForce-803C Maximal GCD(贪心数学)
Maximal GCD CodeForces - 803C 现在给定一个正整数 n.你需要找到 k 个严格递增的正整数 a1, a2, ..., ak,满足他们的和等于 n 并且他们的最大公因数尽量大 ...
- 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 ...
随机推荐
- No qualifying bean of type [java.lang.String] found for dependency: expected
出现这个问题的原因是因为多写了一个注解但是没有实体类.如: 或者其他注解下没有内容.
- swiper.js的使用
点击api文档地址, (1)图片轮播banner <script src="js/jquery-2.1.4.min.js"></script> <sc ...
- 782B. The Meeting Place Cannot Be Changed 二分 水
Link 题意:给出$n$个坐标$x_i$,$n$个速度$v_i$问使他们相遇的最短时间是多少. 思路:首先可肯定最终相遇位置必定在区间$[0,max(x_i)]$中,二分最终位置,判断左右部分各自所 ...
- MDI窗体简单方法(调用,闪屏)
调用方式: RibbonForm mdishow = new RibbonForm(); //实例化 midshow.MdiParent = this; //设置在主窗体,以MDI的方式显示,关键属性 ...
- 强大的jQuery网格插件 ParamQuery
ParamQuery是一种轻量级的jQuery网格插件,基于用于用户界面控制.具有一致API的优秀设计模式jQueryUI Widget factory创建,能够在网页上展示各种类似于Excel和Go ...
- 【BZOJ】1087: [SCOI2005]互不侵犯King
[算法]状态压缩型DP [题解]http://www.cnblogs.com/xtx1999/p/4620227.html (orz) https://www.cnblogs.com/zbtrs/p/ ...
- 【BZOJ】1537: [POI2005]Aut- The Bus
[算法]DP+线段树求区间max(二维偏序) [题解] 状态转移方程:f[i]=max(f[j]+v[i]),x[j]<x[i]&&y[j]<y[i]. 观察j的条件限制显 ...
- 多进程Process
多进程旧式写法 from multiprocessing import Pool def f(x): return x*x if __name__ == '__main__': p = Pool(5) ...
- JodaTime报时区异常错误
在将爬下来的网页解析需要的字段批量入口的时候(逻辑类似下面): @Test public void test_001(){ String TIME = "1990-04-15"; ...
- c语言学习笔记.关键字.存储类型关键字等
关键字const 1.修饰变量. 修饰的对象为常量,只读. 2.修饰指针. const 也可以和指针变量一起使用,这样可以限制指针变量本身,也可以限制指针指向的数据. const 离变量名近就是用来修 ...