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 ...
随机推荐
- MakeDown的使用
Makedown的使用 之前有用博客园来写博客,但是因为它的界面不好看,所以中途就放弃了.后来也使用过"有道云笔记",发现其写的笔记的界面很简洁工整.有道云笔记的书写原理和Make ...
- HDU 3507 单调队列 斜率优化
斜率优化的模板题 给出n个数以及M,你可以将这些数划分成几个区间,每个区间的值是里面数的和的平方+M,问所有区间值总和最小是多少. 如果不考虑平方,那么我们显然可以使用队列维护单调性,优化DP的线性方 ...
- Redis实战(五)CentOS 7上搭建Redis集群
高可用Redis(十二):Redis Cluster https://www.cnblogs.com/renpingsheng/p/9862485.html https://www.cnblogs.c ...
- 配置kernel的log buf大小(如果kmsg log被覆盖)
如果在打印kmsg log时发现log被覆盖,log 的buf不够大可以使用默认配置调buf: defconfig CONFIG_LOG_BUF_SHIFT=20 (默认是17 2的17次方) ...
- juery中循环遍历json数组
var dataList=[]; var stock0={stockcode:"007758",stockname:"商业政7",state:"1&q ...
- 【BubbleCup X】D. Exploration plan
这个题首先一眼能看出二分答案…… 毕竟连可爱的边界都给你了. 下面就是怎么check 首先预处理跑一遍floyed,预处理出最短路. 用网络流判断能否达到即可. #include<bits/st ...
- 读书笔记 effective c++ Item 3 在任何可能的时候使用 const
Const可以修饰什么? Const 关键字是万能的,在类外部,你可以用它修饰全局的或者命名空间范围内的常量,也可以用它来修饰文件,函数和块作用域的静态常量.在类内部,你可以使用它来声明静态或者非 ...
- spring中的任务调度Quartz
Spring 整合 Quartz 任务调度 主要有两种方式. Quartz的官网:http://www.quartz-scheduler.org/ 这两种只是一些配置文件简单配置就OK了,但是根本无法 ...
- linux下rz,sz安装
1.sz rz yum安装 yum install lrzsz
- 手游研发CJ抱大腿指南
文摘要:CJ来了,又是一年一度的游戏圈盛事,随着手游行业的迅速崛起,今年CJ上,手游研发商以及发行商必定成为焦点.由于门槛低.市场热.前景好等因素的影响,国内一下子蹦出一大堆手游研发团队.很幸运(或者 ...