【题目链接】:http://codeforces.com/contest/803/problem/C

【题意】



给你一个数字n;一个数字k;

让你找一个长度为k的序列;

要求这个长度为k的序列的所有数字的和为n;

且这k个数字的最大公因数最大;

【题解】



key:这个最大公因数一定是n的因子!

/*
设最后选出来的k个数字为
a[1],a[2]...a[k];
这些数字的最大公因数为g
g*b[1],g*b[2],...g*b[k]
n=g*b[1]+g*b[2]+...+g*b[k];
这里g必然是n的因子;

n/g==b[1]+b[2]+..+b[k]>=1+2+3...+k···①
(1+2+3..+k 是最小的满足严格递增的长度为k的序列)
构造最后的答案为
1*g,2*g,3*g...(k-1)*g以及n-(1+2+3..k-1)*g
前k-1项肯定是递增的;
而由①式可知
n-g*(1+2+3..+k)>=0

最后一项=n-g*(1+2+3..+k-1)>=g*k
所以也是单调递增的;
这里只要保证①式成立,就肯定能找到解了
(1+2+...+k如果大于1e10直接输出无解就好,这样防止爆LL)
有解就从大到小枚举n的因子,找到第一个符合的输出就好
*/

【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 110; LL n,k;
vector <LL> v1,v2; void out(LL g)
{
LL temp = 0;
for (int i = 1;i <= k-1;i++)
cout <<i*g<<' ',temp+=i*g;
cout << n-temp<<endl;
exit(0);
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false),cin.tie(0);//scanf,puts,printf not use
cin >> n >> k;
if (k>=1e6)
return cout << -1 << endl,0;
LL sumk = (1+k)*k/2;
LL ma = sqrt(n);
for (LL g = 1;g <= ma;g++)
if (n%g==0)
v1.pb(g),v2.pb(n/g);
int len = v2.size();
rep1(i,0,len-1)
{
LL x = v2[i];
if (n/x>=sumk)
out(x);
}
len = v1.size();
rep2(i,len-1,0)
{
LL x = v1[i];
if (n/x>=sumk)
out(x);
}
cout << -1 << endl;
return 0;
}

【codeforces 803C】Maximal GCD的更多相关文章

  1. 【Codeforces 664A】 Complicated GCD

    [题目链接] 点击打开链接 [算法] gcd(a,a+1) = 1 所以当a = b时,答案为a,否则为1 [代码] #include<bits/stdc++.h> using names ...

  2. 【codeforces 340B】Maximal Area Quadrilateral

    [题目链接]:http://codeforces.com/problemset/problem/340/B [题意] 给你n个点,让你在这里面找4个点构成一个四边形; 求出最大四边形的面积; [题解] ...

  3. 【Codeforces 1034A】Enlarge GCD

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 设原来n个数字的gcd为g 减少某些数字之后 新的gcd肯定是g的倍数 即gx 我们可以枚举这个x值(x>=2) 看看原来的数字里面有多 ...

  4. 【CodeForces 624D】Array GCD

    题 You are given array ai of length n. You may consecutively apply two operations to this array: remo ...

  5. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  6. 【UOJ#33】【UR#2】树上GCD 有根树点分治 + 容斥原理 + 分块

    #33. [UR #2]树上GCD 有一棵$n$个结点的有根树$T$.结点编号为$1…n$,其中根结点为$1$. 树上每条边的长度为$1$.我们用$d(x,y)$表示结点$x,y$在树上的距离,$LC ...

  7. 【UOJ#33】【UR #2】树上GCD(长链剖分,分块)

    [UOJ#33][UR #2]树上GCD(长链剖分,分块) 题面 UOJ 题解 首先不求恰好,改为求\(i\)的倍数的个数,最后容斥一下就可以解决了. 那么我们考虑枚举一个\(LCA\)位置,在其两棵 ...

  8. 【codeforces 798C】Mike and gcd problem

    [题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 ...

  9. 【Codeforces 582A】 GCD Table

    [题目链接] 点击打开链接 [算法] G中最大的数一定也是a中最大的数.          G中次大的数一定也是a中次大的数. 第三.第四可能是由最大和次大的gcd产生的 那么就不难想到下面的算法: ...

随机推荐

  1. Python 远程调用MetaSploit

    (1)安装Python的msgpack类库.MSF官方文档中的数据序列化标准就是參照msgpack. root@kali:~# apt-get install python-setuptools ro ...

  2. iOS GCD使用指南

    Grand Central Dispatch(GCD)是异步运行任务的技术之中的一个. 一般将应用程序中记述的线程管理用的代码在系统级中实现.开发人员仅仅须要定义想运行的任务并追加到适当的Dispat ...

  3. 11153 kill boss

    11153 kill boss 时间限制:1000MS  内存限制:65535K提交次数:1090 通过次数:340 题型: 编程题   语言: G++;GCC Description Acmer最近 ...

  4. leetCode 20.Valid Parentheses (有效的括号) 解题思路和方法

    Valid Parentheses  Given a string containing just the characters '(', ')', '{', '}', '[' and ']', de ...

  5. luogu2242 公路维修问题

    题目大意 把一个高速公路看作由连续排列的一个个格子组成,有n个格子上有坑.给出m,要求出m段区间,使得这m区间覆盖到所有坑(交通管制),且占据的格子数量最少.输出占据的格子数. 题解 换个角度看问题. ...

  6. [SCOI 2003] 字符串折叠

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1090 [算法] 区间DP [代码] #include<bits/stdc++. ...

  7. [POJ 2282] The Counting Problem

    [题目链接] http://poj.org/problem?id=2282 [算法] 数位DP [代码] #include <algorithm> #include <bitset& ...

  8. js 对象方法、类方法、原型方法区别

    function People(name){this.name=name;//对象方法this.Introduce=function(){alert("My name is "+t ...

  9. 如何删除github wiki page

    title: 如何删除github wiki page toc: false date: 2019-02-23 10:08:41 categories: methods tags: github wi ...

  10. A - I Wanna Be the Guy

    Problem description There is a game called "I Wanna Be the Guy", consisting of n levels. L ...