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. 通过网址request到response经历的过程

    前言当我们在浏览器中输入一个网址,比如www.google.cn,浏览器就会加载出百度的主页.那么浏览器背后完成的具体是怎么样的呢? 总结起来大概的流程是这样的: (1)浏览器本身是一个客户端,当你输 ...

  2. beebase

    1.简单介绍 BeeBase是一个在线生物信息学数据库,显示与Apis mellifera.欧洲蜜蜂以及一些病原体和其他物种有关的数据.它是与蜜蜂基因组测序联盟合作开发的.BeeBase是蜜蜂研究社区 ...

  3. RepeatMasker

    1.简介 RepeatMasker是一款基于Library-based,通过相似性比对来识别重复序列,可以屏蔽序列中转座子重复序列和低复杂度序列(默认将其替换成N).提供有在线服务.RepeatMas ...

  4. maven <scope>provided</scope>

    今天开发web的时候,需要用到servlet-api,于是在pom.xml中添加依赖 <dependency> <groupId>javax.servlet</group ...

  5. 2.1、CDH 搭建Hadoop在安装(为Cloudera Manager配置存储库)

    步骤1:为Cloudera Manager配置存储库 使用包管理工具安装Cloudera Manager yum 对于RHEL兼容系统, zypper对于SLES,和 apt-get对于Ubuntu. ...

  6. WINDOW 2008多人访问设置

    gpedit.msc,在组策略中对位于“计算机配置->策略->管理模板->Windows 组件->远程桌面服务->远程桌面会话主机->连接”中,限制连接数量中进行配 ...

  7. 进程实时监控pidstat命令详解

    pidstat主要用于监控全部或指定进程占用系统资源的情况,如CPU,内存.设备IO.任务切换.线程等.pidstat首次运行时显示自系统启动开始的各项统计信息,之后运行pidstat将显示自上次运行 ...

  8. pandas_1

    大熊猫10分钟 这是对熊猫的简短介绍,主要面向新用户.您可以在Cookbook中看到更复杂的食谱. 通常,我们导入如下: In [1]: import numpy as np In [2]: impo ...

  9. switch只跟在这些之后

    switch case 可以用在他们之后

  10. Springboot学习03-SpringMVC自动配置

    Springboot学习03-SpringMVC自动配置 前言 在SpringBoot官网对于SpringMVCde 自动配置介绍 1-原文介绍如下: Spring MVC Auto-configur ...