CodeFoorces 803C Maximal GCD
枚举。
枚举$gcd$,然后计算剩下的那个数能不能分成$k$个递增的数。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std; long long b[100010];
long long ans[200010];
int sz;
long long n,k; void init()
{
for(long long i=1;i*i<=n;i++)
{
if(n%i!=0) continue;
b[sz++] =i;
if(i!=n/i) b[sz++] =n/i;
}
} int main()
{
scanf("%lld%lld",&n,&k);
init(); sort(b,b+sz); if(k>200000)
{
printf("-1\n");
return 0;
} int suc=0;
for(int i=sz-1;i>=0;i--)
{
long long sum = n/b[i];
long long p = (1+k)*k/2;
if(p>sum) continue; for(int j=1;j<=k;j++)
{
ans[j] = j;
sum = sum-ans[j];
}
ans[k]+=sum; for(int j=1;j<=k;j++)
{
ans[j]=ans[j]*b[i];
} suc=1;
break;
} if(suc==0)
{
printf("-1\n");
}
else
{
for(long long i=1;i<=k;i++)
{
printf("%lld",ans[i]);
if(i<k) printf(" ");
else printf("\n");
}
} return 0;
}
CodeFoorces 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 二分
C. Maximal GCD time limit per test: 1 second memory limit per test: 256 megabytes input: standard in ...
- 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}$,枚举这 ...
- 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 ...
- CodeForce-803C Maximal GCD(贪心数学)
Maximal GCD CodeForces - 803C 现在给定一个正整数 n.你需要找到 k 个严格递增的正整数 a1, a2, ..., ak,满足他们的和等于 n 并且他们的最大公因数尽量大 ...
- 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 ...
- Codeforces H. Maximal GCD(贪心)
题目描述: H. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard ...
随机推荐
- reset password for local admin on Windows2016 by Powershell
上脚本吧,找半天 $password = "yourpassword" $pwd = $password | ConvertTo-SecureString -asPlainText ...
- swift4.0中http连接(据于xcode9.3 URLSession)
NSURLSession是NSURLConnection的替代者,在2013年苹果全球开发者大会上(WWDC2013)随iOS7一起发布的,是对NSURLConnection进行了重构优化后的新的网络 ...
- powerdesigner中把表的描述复制到Name
'****************************************************************************** '* File: comment2nam ...
- 【Web】Struts之namespace
ZZ:struts2学习:配置篇之namespace 在struts1中是没有命名空间这个概念的,通过命名空间我们可以将所有的action配置划分为一个个逻辑单元,每个单元都有它自己的标识前缀.命名控 ...
- ZOJ 3774 Fibonacci的K次方和
In mathematics, Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers of the f ...
- (64位)本体学习程序(ontoEnrich)系统配置说明文档
1系统环境 64位 Ubuntu 2 第三方依赖库配置 boost_1_44_0 #解压boost_1_44_0.tar.gz 到 /usr/local.如果出现权限问题,请用sudo执行该命令 ta ...
- CodeForces 990B
You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, u ...
- CSS Sprite笔记
1. 什么是CSS Sprite 将一些碎小的图片拼接为一张大点的图片来使用,目的是为了减少浏览器的http请求次数以提高网页的加载速度.每次请求图片都需要跟服务器建立一次连接,并且浏览器的最大并发请 ...
- 【译】第三篇 SQL Server代理警报和操作员
本篇文章是SQL Server代理系列的第三篇,详细内容请参考原文. 正如这一系列的上一篇所述,SQL Server代理作业是由一系列的作业步骤组成,每个步骤由一个独立的类型去执行,除了步骤中执行的工 ...
- 常用的css3新特性总结
1:CSS3阴影 box-shadow的使用和技巧总结: 基本语法是{box-shadow:[inset] x-offset y-offset blur-radius spread-radiuscol ...