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

题意:输出递增的k个数,使得他们的和等于n并且它们的GCD最大。 不存在输出-1。

思路:二分n的约数。(1+k)*k<=n是才存在k个符合要求的数,否者输出-1。

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn=2e5+,inf=0x3f3f3f3f,mod=1e9+;
const ll MAXN=1e13+;
ll n,k,sum;
ll sign[maxn];
int check(ll q)
{
if(sum*q<=n) return ;
else return ;
}
int main()
{
scanf("%lld%lld",&n,&k);
if(k>=1e6)
{
cout<<-<<endl;
return ;
}
sum=(+k)*k/;
if(sum>n)
{
cout<<-<<endl;
return ;
}
ll l=,r=,q=;
for(ll i=; i*i<=n; i++)
if(n%i==) sign[++r]=i,sign[++r]=n/i;
sort(sign+,sign+r+);
while(l<=r)
{
ll mid=(l+r)/;
if(check(sign[mid])) l=mid+,q=sign[mid];
else r=mid-;
}
ll cou=;
for(int i=; i<k; i++)
{
cout<<q*i<<" ";
cou+=q*i;
}
cout<<n-cou<<endl;
return ;
}

Codeforces 803C. Maximal GCD 二分的更多相关文章

  1. codeforces 803C Maximal GCD(GCD数学)

    Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...

  2. CodeForces - 803C Maximal GCD 【构造】

    You are given positive integer number n. You should create such strictly increasing sequence of k po ...

  3. Codeforces 803C. Maximal GCD

    题目链接:http://codeforces.com/contest/803/problem/C 中了若干trick之后才过... k个数的严格递增序列最小权值和就是${n*(n+1)/2}$,枚举这 ...

  4. Codeforces H. Maximal GCD(贪心)

    题目描述: H. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. CodeFoorces 803C Maximal GCD

    枚举. 枚举$gcd$,然后计算剩下的那个数能不能分成$k$个递增的数. #include <iostream> #include <cstdio> #include < ...

  6. 【数学】codeforces C. Maximal GCD

    http://codeforces.com/contest/803/problem/C [题意] 给定两个数n,k(1 ≤ n, k ≤ 10^10) 要你输出k个数,满足以下条件: ①这k个数之和等 ...

  7. AC日记——Maximal GCD codeforces 803c

    803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...

  8. Maximal GCD CodeForces - 803C (数论+思维优化)

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

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

随机推荐

  1. 转换es6

    { "presets": [["env", { "modules": false }],"stage-3"," ...

  2. 03_java基础(一)之计算机应用知识普及

    1.计算机(Computer) 全称:电子计算机,俗称电脑.是一种能够按照程序运行,自动.高速处理海量数据的现代化智能电子设备.由硬件和软件所组成,没有安装任何软件的计算机称为裸机.常见的形式有台式计 ...

  3. 第五篇:jmeter图形监控扩展

    插件下载:http://jmeter-plugins.org/downloads/all/ 插件: 1.首先将jmeterPluging.jar包复制到jmeter的lib目录下面的ext目录下面,然 ...

  4. cdnbest节点安装后连不上cdn主控原因排查

    1. 查看节点程序是否启动 ps -aux |grep kangle 2. 登陆cdn节点用telnet命令查下和主控的通信,命令:telnet 主控ip 3320 3. 如果节点程序都有启动,可查看 ...

  5. c#实现动态加载Dll(转)

    c#实现动态加载Dll 分类: .net2009-12-28 13:54 3652人阅读 评论(1) 收藏 举报 dllc#assemblynullexceptionclass 原理如下: 1.利用反 ...

  6. defer和async的详细区别

    看过javascript高级程序设计的人,在javascript高级程序设计里,应该看到了介绍了有关defer和async的区别,可是比较浅显,而且也说得不是很清楚.下面我们来通过图片来详细了解下df ...

  7. numpy学习之矩阵之旅

    一:特殊的矩阵 1.全0全1的矩阵 2.单位矩阵 单位矩阵:整个矩阵是n*n的,并且斜对角全是1 矩阵的加减法 1.矩阵相加,相减必须要有相同的行和列 二:数组的乘法(点成) 数组的乘法 list_1 ...

  8. 贪吃蛇GamePanel Java实现(二)

    package cn.tcc.snake.tcc.View; import java.awt.Color;import java.awt.Graphics; import javax.swing.JP ...

  9. 牛客练习赛19 E和F(签到就走系列)托米的饮料+托米搭积木

    E题传送门:点我 F题传送门:点我 可爱的小托米得到了n瓶饮料. 但他不小心把开盖的工具弄丢了,所以他只能利用饮料瓶来开盖. 已知第i个瓶子的品牌为ai,且其能打开bi品牌的瓶子. 问有几瓶饮料托米无 ...

  10. JAVA去重

    JAVA中去掉空格 1. String.trim() trim()是去掉首尾空格 2.str.replace(" ", ""); 去掉所有空格,包括首尾.中间 ...