Educational Codeforces Round 20 C 数学/贪心/构造
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 的数列,gcd尽可能的大.
题解:gcd 从1~i 所以寻找长度为k 首项为i 等差为i 数列和为n的一个序列
细细考虑 n应当模尽i 那么枚举n的因子 check 一下 取最大的i
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#define ll __int64
using namespace std;
ll n,k;
bool fun(ll s){
if(k*(k+)*s/>n)
return false;
if((n-k*(k-)*s/)%s==)
return true;
return false;
}
int main()
{
scanf("%I64d %I64d",&n,&k);
if(k>(*n/(+k)))
printf("-1\n");
else
{
ll e=;
for(ll i=;i*i<=n;i++){
if(n%i==&&fun(i)) e=max(e,i);
if(n%i==&&fun(n/i)) e=max(e,n/i);
}
for(int j=; j<k; j++)
printf("%I64d ",j*e);
printf("%I64d\n",n-k*(k-)*e/);
}
return ;
}
Educational Codeforces Round 20 C 数学/贪心/构造的更多相关文章
- Educational Codeforces Round 20
Educational Codeforces Round 20 A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...
- Educational Codeforces Round 53C(二分,思维|构造)
#include<bits/stdc++.h>using namespace std;const int N=1e6+6;int x[N],y[N];int sx,sy,n;char s[ ...
- 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 64 -B(贪心)
题目链接:https://codeforces.com/contest/1156/problem/B 题意:给一段字符串,通过变换顺序使得该字符串不包含为位置上相邻且在字母表上也相邻的情况,并输出. ...
- Educational Codeforces Round 15 D 数学推公式
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- 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. Maximal GCD
C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 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 ...
随机推荐
- Select 、Poll 和 Epoll
作用 Epoll 和 Select 的作用都是为了多I/O同步复用的问题,利用Epoll.Poll或Select函数指定内核监听多个I/O的读.写.异常事件,避免每一个I/O都指定一个处理线程,导致开 ...
- mysql 5.5 zip配置安装
1.解压2.创建option文件 --defaults-file=../my.ini [mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 [mys ...
- 在Emacs 23里字体的调整(转自ChinaUnix.net)
首先,在Emacs中,通过菜单Options --> Set Default Font,设置好你喜欢的字体. 然后,把光标放到你所在的字体上,用命令M-x describe-font来查看你当前 ...
- ORA-01747
java.sql.SQLException: ORA-01747: user.table.column, table.column 或列说明 语法中多了逗号 或者字段使用关键字
- 王者荣耀交流协会final发布中间产物
WBS+PSP 版本控制报告 软件功能说明书final修订
- gitLab服务器搭建+ rundeck自动化部署
git服务器搭建 https://blog.csdn.net/gx_1_11_real/article/details/79406427 rundeck 部署 https://blog.csdn. ...
- Spring学习(五)——Spring注解(一)
---恢复内容开始--- 概述 注释配置相对于 XML 配置具有很多的优势: 它可以充分利用 Java 的反射机制获取类结构信息,这些信息可以有效减少配置的工作.如使用 JPA 注释配置 ORM 映射 ...
- MySQL 查询缓存机制(MySQL数据库调优)
查询缓存机制:缓存的是查询语句的整个查询结果,是一个完整的select语句的缓存结果 哪些查询可能不会被缓存 :查询中包含UDF.存储函数.用户自定义变量.临时表.mysql库中系统表.或者包含列级别 ...
- 【Leetcode】50. Pow(x, n)
Implement pow(x, n). Example 1: Input: 2.00000, 10 Output: 1024.00000 Example 2: Input: 2.10000, 3 O ...
- (十二)Jmeter之Bean Shell的使用(一)
一.什么是Bean Shell BeanShell是一种完全符合Java语法规范的脚本语言,并且又拥有自己的一些语法和方法; BeanShell是一种松散类型的脚本语言(这点和JS类似); BeanS ...