Educational Codeforces Round 20 C. Maximal GCD
1 second
256 megabytes
standard input
standard output
You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.
If there is no possible sequence then output -1.
The first line consists of two numbers n and k (1 ≤ n, k ≤ 1010).
If the answer exists then output k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.
6 3
1 2 3
8 2
2 6
5 3
-1
暴力枚举,k个数都是n的因子
n - s > (k - 1)·d.然后从d枚举到n/d就好了,这个思路我是想不到的,听打神讲的,然而我还写不出来,抄了大神的代码,CF这样很好啊。帮助小白进阶,从哪里开始枚举
自己要想清楚
#include <cstdio>
typedef long long ll;
int main()
{
ll n, k;
scanf("%lld%lld", &n, &k);
if (k > (ll)1e8)
{
printf("-1\n");
return ;
}
ll b = n / (k * (k + ) / );
if (b == )
{
printf("-1\n");
return ;
}
ll r = ;
for (ll x = ; x * x <= n; x++)
{
if (n % x != ) continue;
if (x <= b && x > r) r = x;
if (n / x <= b && n / x > r) r = n / x;
}
for (int i = ; i < k; i++)
printf("%lld ", r * i);
n -= r * k * (k - ) / ;
printf("%lld\n", n); return ;
}
Educational Codeforces Round 20 C. Maximal GCD的更多相关文章
- Educational Codeforces Round 20 A. Maximal Binary Matrix
A. Maximal Binary Matrix time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Educational Codeforces Round 20
Educational Codeforces Round 20 A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...
- Educational Codeforces Round 20.C
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Educational Codeforces Round 20 C 数学/贪心/构造
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Educational Codeforces Round 20 D. Magazine Ad
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad ...
- Educational Codeforces Round 20 C(math)
題目鏈接: http://codeforces.com/problemset/problem/803/C 題意: 給出兩個數n, k, 將n拆分成k個數的和,要求這k個數是嚴格遞增的,並且這k個數的g ...
- Educational Codeforces Round 20 A
Description You are given matrix with n rows and n columns filled with zeroes. You should put k ones ...
- Educational Codeforces Round 20 B. Distances to Zero
B. Distances to Zero time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Educational Codeforces Round 20 E - Roma and Poker(dp)
传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 ...
随机推荐
- 用指针的方式实现,重写strrchr函数的功能
char *strchrTest(char * ptr,char c); Action(){ char str[]={"thisisadog"}; char c='s'; lr_o ...
- 地址栏传值 JS取值方法
function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...
- nginx只允许域名访问网址,禁止ip访问
修改nginx配置 文件 在server段里插入如下正则: if ( $host != 'www.baidu.com') { return 403; } 说明:如果访问讨还不是www.baidu.co ...
- HDU - 5491 The Next 2015 ACM/ICPC Asia Regional Hefei Online
从D+1开始,对于一个数x,区间[x,x+lowbit(x))内的数字的二进制位上1的数量整体来说是单调不减的,因此可快速得出1在这个区间的取值范围. 每次判断一下有没有和[s1,s2]有没有交集,一 ...
- 二、antd pro 删除eslint检测
删除package.json 里 " pre-commit": "npm run lint-staged" 这个对象就可以.
- targetcli save error
iscsi configuration unable to save python error “ValueError: 'Implict and Explict' is not in list” / ...
- SC || Chapter 3
┉┉∞ ∞┉┉┉┉∞ ∞┉┉┉∞ ∞┉┉ 基本数据类型 && 对象数据类型 基本数据类型(int char long) 在栈中分配内存,不可变 对象数据类型(String BigInt ...
- java中栈、堆和方法区的关系
另外,常量池在方法区中
- 利用Vue.js实现登录/登出以及JWT认证
JSON Web Token 入门教程:http://www.ruanyifeng.com/blog/2018/07/json_web_token-tutorial.html 后端代码地址:https ...
- ORACLE中RECORD、VARRAY、TABLE、IS REF CURSOR 的使用及实例详解
ORACLE中RECORD.VARRAY.TAB.IS REF CURSOR LE的使用及实例详解 create or replaceprocedure PRO_RECORD_ROW_TAB_EXAM ...