Codeforces 803C. Maximal GCD 二分
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
题意:输出递增的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 二分的更多相关文章
- codeforces 803C Maximal GCD(GCD数学)
Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...
- CodeForces - 803C Maximal GCD 【构造】
You are given positive integer number n. You should create such strictly increasing sequence of k po ...
- Codeforces 803C. Maximal GCD
题目链接:http://codeforces.com/contest/803/problem/C 中了若干trick之后才过... k个数的严格递增序列最小权值和就是${n*(n+1)/2}$,枚举这 ...
- Codeforces H. Maximal GCD(贪心)
题目描述: H. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CodeFoorces 803C Maximal GCD
枚举. 枚举$gcd$,然后计算剩下的那个数能不能分成$k$个递增的数. #include <iostream> #include <cstdio> #include < ...
- 【数学】codeforces C. Maximal GCD
http://codeforces.com/contest/803/problem/C [题意] 给定两个数n,k(1 ≤ n, k ≤ 10^10) 要你输出k个数,满足以下条件: ①这k个数之和等 ...
- AC日记——Maximal GCD codeforces 803c
803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...
- Maximal GCD CodeForces - 803C (数论+思维优化)
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 ...
随机推荐
- ADO.Net 数据库修改
数据库的修改方法和增加一样,只是把增加语句换成了修改语句,后面执行语句是相同的 首先也是需要获取并接收输入的要修改的哪个数据以及修改后的数据 代码演示: using System; using Sys ...
- GPS卫星定位防盗系统机芯
GPS卫星定位防盗系统机芯,一般安装在驾驶室的操作台内,包括GPS模块,安装时需要先把车门打开,并把两边的车门拆卸下来,才能拆卸驾驶仪表台,再按说明书安装GPS定位防盗机芯,同时置于4A/12V免维护 ...
- RepeatMasker
1.简介 RepeatMasker是一款基于Library-based,通过相似性比对来识别重复序列,可以屏蔽序列中转座子重复序列和低复杂度序列(默认将其替换成N).提供有在线服务.RepeatMas ...
- target=_blank攻击
[target=_blank攻击] 在<a>标签中加入 rel="noopener noreferrer" 来避免. 参考:https://mathiasbynens. ...
- metasploit framework(十四):弱点扫描
vnc 密码破解 vnc 端口5900 先开启数据库 启动msf vnc无密码访问 RDP远程桌面漏洞 win7 192.168.1.123 xp 192.168.1.122 发现有两个模块, ...
- linux命令清除服务器缓存
linux 服务器开了某项服务或程序后,内存占用的非常大,停止服务或关闭进程后,内存不会立即释放,需要手动释放,使用命令 echo 3 > /proc/sys/vm/drop_chaches 释 ...
- Java Web开发和Python Web开发之间的区别
今天的文章讨论了Java Web开发和Python Web开发之间的区别.我不鼓励我们在这里从Java Web迁移到Python Web开发.我只是想谈谈我的感受.它不一定适合所有情况,仅供我们参考. ...
- openvpn-admin(openvpn web管理 )
openvpn 两种认证简介: 1.key分发: 在服务器端生成秘钥,然后下载到本地,将服务器端的ca.crt xx.crt xx.key ta.key(如果服务器启用的话需要,未开启的话不需要,功能 ...
- 原生js实现一个简单的轮播图
想锻炼一下自己的原生js能力可以从写一个轮播图开始,轮播图的运用想必大家都知道吧,好了废话不多说,开始记笔记了,一些需要注意的点,我都在代码中标注了 首先是构造html: <div id=&qu ...
- DC之setup-hold time详解
转自一下站点: http://www.blogbus.com/bb2hh-logs/20463915.html