codeforces/contest/803/problem C
题意:输入n,k.将n拆成k个数的序列,使得这k个数的gcd最大。(且序列严格递增)。1 ≤ n, k ≤ 1010 。
分析:假设k个数的gcd为d,则一定有d|n,(即d一定是n的因子);遍历n所有的因子到
即可。不要忘记考虑d和
的情况。
代码:
/*
Problem: C. Maximal GCD
Time: 2017/5/4/19:29
*/ #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#define ll long long
#define inf 100000000
#define N 1000000
using namespace std; int main()
{
ll n,k;
scanf("%I64d%I64d",&n,&k);
if(k>(ll)1e6){printf("-1\n");return ;} ll ma=n*/k/(k+);
if(ma==){printf("-1\n");return ;}
ll ans=;
for(ll i=;i<=sqrt(n);i++)
{
if(n%i==)
{
if(i<=ma&&i>ans) ans=i;
if((n/i)<=ma&&(n/i)>ans) ans=n/i;
}
}
for(ll i=;i<k;i++)
printf("%I64d ",ans*i);
printf("%I64d\n",n-ans*k*(k-)/);
return ;
}
codeforces/contest/803/problem C的更多相关文章
- codeforces.com/contest/325/problem/B
http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...
- codeforces Round 286# problem A. Mr. Kitayuta's Gift
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked ...
- 【动态规划】Codeforces 706C Hard problem
题目链接: http://codeforces.com/contest/706/problem/C 题目大意: n(2 ≤ n ≤ 100 000)个字符串(长度不超过100000),翻转费用为Ci( ...
- Codeforces C. NP-Hard Problem 搜索
C. NP-Hard Problem time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Educational Codeforces Round 32 Problem 888C - K-Dominant Character
1) Link to the problem: http://codeforces.com/contest/888/problem/C 2) Description: You are given a ...
- [codeforces contest 1119 F] Niyaz and Small Degrees 解题报告 (树形DP+堆)
interlinkage: http://codeforces.com/contest/1119/problem/F description: 有一颗$n$个节点的树,每条边有一个边权 对于一个$x$ ...
- codeforces 1288D. Minimax Problem(二分)
链接:https://codeforces.com/contest/1288/problem/D D. Minimax Problem 题意:给定n个数组,长度为m,从n中数组挑选两个数组,两个数组中 ...
- CodeForces 1006E Military Problem(DFS,树的选择性遍历)
http://codeforces.com/contest/1006/problem/E 题意: 就是给出n,m,共n个点[1,n],m次询问.第二行给出n-1个数a[i],2<=i<=n ...
- codeforces 340C Tourist Problem
link:http://codeforces.com/problemset/problem/340/C 开始一点也没思路,赛后看别人写的代码那么短,可是不知道怎么推出来的啊! 后来明白了. 首先考虑第 ...
随机推荐
- 【git】idea /git bash命令 操作分支
1.需求 因为目前要对项目做一些改动,而项目又即将上线,这些新的改动又不需要一起上线,所以这个时候需要在原有的master分支上重新拉出一个分支进行开发. 2.分支操作 打开git bash工具→切换 ...
- Python内置函数(8)——bytes
英文文档: class bytes([source[, encoding[, errors]]]) Return a new “bytes” object, which is an immutable ...
- VM14安装Mas os 13
工具/原料 VMware Workstation unlocker(for OS X 插件补丁) macOS 10.13镜像 vmware tools 安装前准备 1 下载以上文件: 1. ...
- C语言中你可能不熟悉的头文件(stdlib.h)
C语言中你可能不熟悉的头文件<cstdlib>(stdlib.h) C Standard General Utilities Library (header) C标准通用工具库(头文件) ...
- CentOs~程序部署那些事
永久更新中…… 主要说一下在centos里,在安装程序和监控程序时,用到的一些常用的命令,希望可以帮到大家! 远程安装程序包:yum install 程序包名 下载程序包:wget 程序包地址 解压t ...
- Netty源码分析(四):EventLoopGroup
无论服务端或客户端启动时都用到了NioEventLoopGroup,从名字就可以看出来它是NioEventLoop的组合,是Netty多线程的基石. 类结构 NioEventLoopGroup继承自M ...
- 创建简单WEB高可用集群
1. 环境介绍 我这里弄了2个虚拟机,信息如下: node1:192.168.168.201 node2:192.168.168.202 2.配置主机名 [root@node1 ~]# vim /et ...
- ES6躬行记(18)——迭代器
ES6将迭代器和生成器内置到语言中,不仅简化了数据处理和集合操作,还弥补了for.while等普通循环的不足,例如难以遍历无穷集合或自定义的树结构等. 迭代器(Iterator)是一种用于迭代的对象, ...
- VS2015安装水晶报表
最近在做一个打印功能,本来是不想用水晶报表的.想直接用微软原生的报表rdlc完成,但是整了一个上午老是打印乱码,且网上找资料找也找不出. 无奈放弃,然后就想到用水晶报表了,以前用过水晶报表,不过一直都 ...
- JDK源码分析(四)—— ConcurrentHashMap
一.概述 ConcurrentHashMap是Java5中新增加的一个线程安全的Map集合,可以用来替代HashTable. 锁分段技术 原理:将数据分成一段一段的存储,然后给每一段数据配一把锁,当一 ...