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 现在给出一个字符串 ...
随机推荐
- 如何提高Mysql的查询效率???
1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...
- SQL SERVER之填充因子
建SQL SERVER索引的时候有一个选项,即Fillfactor(填充因子). 这个可能很少人会去注意它,但它也是比较重要的.大家可能也都知道有这个东西,但是如何去使用它,可能会比较迷糊.另外,即使 ...
- javaSe-线程2
package com.java.chap09.sec02; public class Thread3 implements Runnable{ private int baoZi=1; privat ...
- 字符串转换JSON 的方法
function (sJSON) { if (window.JSON) { return window.JSON.parse(sJSON); } else { return eval('(' + sJ ...
- CornerStone使用跳坑总结
Cornerstone是专门为Mac用户设计的Subversion(SVN)的控制,使版本控制更加透明.cornerstone根Xcode相比,能够更好的忽略文件,所以除了项目经理第一次初始化项目的时 ...
- FTPClient:enterLocalPassiveMode()方法简单说明
问题:在Java程序中,使用FTPClient下载FTP文件的时候,可以下载到FTP服务器上的文件夹,但是里面的文件没有下载到本地. 分析:这个涉及到FTP在使用的过程中,客户端和服务端连接过程中,端 ...
- 抓取oracle建表语句及获取建表ddl语句
抓取oracle建表语句及获取建表ddl语句 1.抓取代码如下: 1.1.产生表的语法资料 DECLARE-- v_notPartTable VARCHAR2(1000):= '&2'; -- ...
- 【单调队列】P1886 滑动窗口
GET 单调队列 题目描述 现在有一堆数字共N个数字(N<=10^6),以及一个大小为k的窗口.现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗口中的最大值和最小值. 例如: Th ...
- day3-python 登录
import datetime # 1. f = open('users') result = f.read() f.close() user_list = result.split() # user ...
- VMware虚拟网卡介绍和使用说明
介绍VMware三种网络连接模式的详细配置及规则 版权声明:本文为博主原创文章,未经博主允许不得转载. 原文地址: https://www.cnblogs.com/poterliu/p/9455391 ...