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 ...
随机推荐
- Java集合框架(list,Queue)
List和Queue都继承自Collection接口 list常规用法 List判断两个对象相等的标准:equals方法返回true class A2 { public boolean equals( ...
- UVA 12063 Zeros and Ones
https://vjudge.net/problem/UVA-12063 题意: 统计n为二进制数中,0和1相等且值为m的倍数的数有多少个 dp[i][j][k] 前i位二进制 有j个1 值模m等于k ...
- Elasticsearch——QueryBuilder简单查询
elasticsearch中存储的全部文档 1.matchAllQuery() matchAllQuery()方法用来匹配全部文档 public class QueryTest { pub ...
- SpringCloud入门系列(一)
https://www.cnblogs.com/edisonchou/p/java_spring_cloud_foundation_sample_list.html
- LintCode 539: Move Zeroes
终于下决心开始刷题了! 选择LintCode而不是LeetCode主要是因为LintCode操作更顺手,希望能够坚持下去. 还是循序渐进吧,数据结构和算法的东西很久没碰都很生疏了,先找找感觉. 这是一 ...
- 读书笔记 ~ Python黑帽子 黑客与渗透测试编程之道
Python黑帽子 黑客与渗透测试编程之道 <<< 持续更新中>>> 第一章: 设置python 环境 1.python软件包管理工具安装 root@star ...
- 购物车中的input输入框只能输入数字和输入为0的时候默认为1
<input type="text" value="1" onkeyup="value=(parseInt((value=value.repla ...
- Ubuntu 各版本的几个国内更新源
Ubuntu 国内更新源(各版本通用) 前言:为了下载更方便,速度更快,我们在使用Linux系列系统时修改 apt源 为国内的源 1.复制源文件备份,以防万一 修改文件sources.list,在目录 ...
- redis源码分析——aofrewrite
随着redis的运行,aof会不断膨胀(对于一个key会有多条aof日志),导致通过aof恢复数据时,耗费大量不必要的时间.redis提供的解决方案是aof rewrite.根据db的内容,对于每个k ...
- [ python ] 作业:选课系统
功能代码实现源地址:https://www.cnblogs.com/lianzhilei/p/5832691.html 如有侵权,立即删除 本文主要是分析 选课系统 实现思路及上面代码的实现过程 ...