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 和为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 数学/贪心/构造的更多相关文章

  1. Educational Codeforces Round 20

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

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

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

  4. Educational Codeforces Round 20 C(math)

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

  5. Educational Codeforces Round 64 -B(贪心)

    题目链接:https://codeforces.com/contest/1156/problem/B 题意:给一段字符串,通过变换顺序使得该字符串不包含为位置上相邻且在字母表上也相邻的情况,并输出. ...

  6. Educational Codeforces Round 15 D 数学推公式

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. Educational Codeforces Round 20.C

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

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

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

随机推荐

  1. 在jre1.8版本下,使用ikvm将jar转换为dll,以供c#调用

    由于合作方使用.net编程,jar包不能用,需要转换成dll格式,来回转换了十几个dll文件(心塞..),终于生成了一个可用的.在这里将走过的弯弯绕绕总结下,希望遇到相似问题的同好们,能走得顺利些. ...

  2. 软件工程第九周psp

    1.PSP表格 2.进度条 3.饼状图 4.折线图

  3. python struct详解

    转载:https://www.cnblogs.com/gala/archive/2011/09/22/2184801.html 有的时候需要用python处理二进制数据,比如,存取文件,socket操 ...

  4. JDK源码分析 – HashMap

    HashMap类的申明 HashMap的定义如下: public class HashMap<K,V> extends AbstractMap<K,V> implements ...

  5. scala程序运行的几种方式

    HelloWorld简单实例 object HelloWorld{ def main(args:Array[String]){ println("HelloWorld") } } ...

  6. OSG学习:使用OSG中预定义的几何体

    常用的内嵌几何体包括: osg::Box //正方体 osg::Capsule //太空舱 osg::Cone //椎体 osg::Cylinder //柱体 osg::HeightField //高 ...

  7. apache反向代理服务器

    1 正向代理: 客户端无法直接访问外部的web,需要在客户端所在的网络内架设一台代理服务器,客户端通过代理服务器访问外部的web(需要在客户端的浏览器中设置代理服务器) 适用于: ①局域网的代理服务器 ...

  8. (八)Jmeter怎么通过后置处理器去做关联

     一.Jmeter关联的方式: Jmeter中关联可以在需要获取数据的请求上 右键-->后置处理器 选择需要的关联方式,如下图有很多种方法可以提取动态变化数据: 二.正则表达式提取器: 1.比如 ...

  9. Windows连接Linux服务器中MySQL数据库-权限配置

    问题描述 在Windows系统中安装了监控MySQL数据库服务器性能的工具Spotlight on MySQL,利用Spotlight连接Linux服务器中的MySQL,进行相关配置如下:   点击& ...

  10. (windows下的)Apache无法启动解决 the requested operation has failed

     以下文章是转载别人的,这里只做学习用 ============================================================================== ...