C. Maximal GCD
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

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.

Input

The first line consists of two numbers n and k (1 ≤ n, k ≤ 1010).

Output

If the answer exists then output k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.

Examples
input
6 3
output
1 2 3
input
8 2
output
2 6
input
5 3
output
-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的更多相关文章

  1. Educational Codeforces Round 20

    Educational Codeforces Round 20  A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...

  2. 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 ...

  3. Educational Codeforces Round 20 C(math)

    題目鏈接: http://codeforces.com/problemset/problem/803/C 題意: 給出兩個數n, k, 將n拆分成k個數的和,要求這k個數是嚴格遞增的,並且這k個數的g ...

  4. Educational Codeforces Round 20 C 数学/贪心/构造

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. Educational Codeforces Round 20 E - Roma and Poker(dp)

    传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 ...

  9. Educational Codeforces Round 20 B

    Description You are given the array of integer numbers a0, a1, ..., an - 1. For each element find th ...

随机推荐

  1. 关于Cookie安全性设置的那些事

    一.标题:关于Cookie安全性设置的那些事 副标:httponly属性和secure属性解析 二.引言 经常有看到XSS跨站脚本攻击窃取cookie案例,修复方案是有httponly.今天写出来倒腾 ...

  2. 1.搭建Maven 多模块应用 --Intellij IDEA 2016.3.5

    1.打开IDEA,file->new ->project  新建工程 2.建成的项目如下图,然后新建java class 模块: 右击工程名->new -> Module 3. ...

  3. 关于php中id设置自增后不连续的问题

    alter table tablename drop column id;alter table tablename add id mediumint(8) not null primary key ...

  4. 一个IT人员实用的工具:Tmux

    1.Tmux安装 tmux下载地址: http://sourceforge.net/projects/tmux/files/tmux/tmux-1.6/tmux-1.6.tar.gz/download ...

  5. DATA VISUALIZATION – PART 1

    Introduction to Data Visualization – Theory, R & ggplot2 The topic of data visualization is very ...

  6. 决策树模型比较:C4.5,CART,CHAID,QUEST

    (1)C4.5算法的特点为: 输入变量(自变量):为分类型变量或连续型变量. 输出变量(目标变量):为分类型变量. 连续变量处理:N等分离散化. 树分枝类型:多分枝. 分裂指标:信息增益比率gain ...

  7. NetFramework各个版本的特性笔记

    公式记忆: .Net 2.0=CLR+BCL+C#(VB.Net)+Win Form+Web Form .Net 3.0=.Net 2.0+WCF+WPF+WF+WCS .Net 3.5=.Net 3 ...

  8. CSS小技巧-怎样让每行多余的文字显示文省略号?

    1.white-space:nowrap 如果是中文,则需要设置行末不断行 2.overflow:hidden 设置超出控件范围隐藏 3.text-overflow:ellipsis

  9. 【FPGA】高斯白噪声的Verilog实现

    本文章主要讨论高斯白噪声的FPGA实现.简单的方法可以采用在Matlab中产生服从一定均值和方差的I.Q两路噪声信号.然后将两组数据存在FPGA中进行回放,以此来产生高斯白噪声.这种方法优点是产生方法 ...

  10. 高CPU、数据库无法读写的真凶

    有兴趣的同学可以参考如下系列文章,都是针对dump分析的实战和总结: Windbg DUMP分析(原创汇总) http://www.cnblogs.com/LoveOfPrince/p/6653341 ...