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项数列使其满足:
1.各项之和为n 2.单增 3.最大公约数最大化。
思路:枚举n的因子q,找到满足n/q>=k*(k+1)/2 的最大q, 输出数列
PS:这题坑点挺多的。。比如数据范围 n,k 都是1e10 特判要考虑到这点。
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define db double
using namespace std;
;
;
int main()
{
ll n,k;
db s=sqrt(2.0);
scanf("%lld%lld",&n,&k);
ll ans=n;
)/) {//必须要判断k的值,否则会溢出。
puts("-1");
;
}
ll ma=;
;i<=sqrt(n);i++){
&&n/i>=k*(k+)/){ //i,n/i都可能是最大因子
ma=max<ll>(ma,i);
)/) ma=max<ll>(ma,n/i);
}
}
;i<k;i++){
printf("%lld ",i*ma);
ans-=i*ma;
}
printf("%lld\n",ans);
}
Educational Codeforces Round 20.C的更多相关文章
- Educational Codeforces Round 20
Educational Codeforces Round 20 A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...
- 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 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 ...
- 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 E - Roma and Poker(dp)
传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 ...
- Educational Codeforces Round 20 B
Description You are given the array of integer numbers a0, a1, ..., an - 1. For each element find th ...
随机推荐
- 解决Cornerstone不能上传.a文件的问题 Cornerstone不上传*.xcuserstate,*.xcbkptlist文件
在使用CornerStone的时候经常会出现.a文件无法上传的问题,导致从svn checkout到本地的时候编译报错 这里可以通过配置CornerStone来达到上传.a文件的效果 操作步骤: 打开 ...
- SCAU Individual Contest #1
总结一下就是自己太弱.每次打比赛遇到比较难题就喜欢瞎开题,结果都是每题想一下,然后就是结束了. A:题意让你用小写字母构造一个总共有K个的回文串,比如aba的话就是{a}{b}{a}{aba}四个,比 ...
- redis入门指南-附录A
- 014 一对多关联映射 单向(one-to-many)
在对象模型中,一对多的关联关系,使用集合来表示. 实例场景:班级对学生:Classes(班级)和Student(学生)之间是一对多的关系. 多对一.一对多的区别: 多对一关联映射:在多的端加入一个外键 ...
- 使用Spring MVC构建REST风格WEB应用
转自:http://fancy888.iteye.com/blog/1629120 对于运行在网络上的MIS系统而言,处理数据的是整个系统的主要任务,翻开程序我们可以看到,80%以上的代码都在处理数据 ...
- zookeeper3.4.9 centos6.5 集群安装
安装jdk http://www.cnblogs.com/xiaojf/p/6568426.html [root@m1 jar]# .tar.gz -C ../ [root@m1 jar]# cd . ...
- ECS_8080端口连接拒绝问题排查
原文链接 用户ECS网络设置 上图是用户ECS的网络示意图: ecs处于vpc网络下 ecs加入了一个安全组,该安全组出入方向均开放8080端口 ecs有两个网卡,一个私网主网卡(有虚线的网卡),一个 ...
- 刨根究底字符编码之十一——UTF-8编码方式与字节序标记
UTF-8编码方式与字节序标记 一.UTF-8编码方式 1. 接下来将分别介绍Unicode字符集的三种编码方式:UTF-8.UTF-16.UTF-32.这里先介绍应用最为广泛的UTF-8. 为满足基 ...
- 热部署环境下,dubbo序列化的bug和优化
一.问题的发现与解决 (1) 在热部署下,使用dubbo的序列化一个pojo对象,反序列化时报错:ClassNotFoundException. 最后发现原因是我们的框架选择使用了java序列 ...
- 【小练习06】HTML+CSS--教学大讲堂
要求实现如下效果图: 代码演示 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...