题目:C. Maximal GCD

题意:输入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的更多相关文章

  1. codeforces.com/contest/325/problem/B

    http://codeforces.com/contest/325/problem/B B. Stadium and Games time limit per test 1 second memory ...

  2. 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 ...

  3. 【动态规划】Codeforces 706C Hard problem

    题目链接: http://codeforces.com/contest/706/problem/C 题目大意: n(2 ≤ n ≤ 100 000)个字符串(长度不超过100000),翻转费用为Ci( ...

  4. Codeforces C. NP-Hard Problem 搜索

    C. NP-Hard Problem time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  5. 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 ...

  6. [codeforces contest 1119 F] Niyaz and Small Degrees 解题报告 (树形DP+堆)

    interlinkage: http://codeforces.com/contest/1119/problem/F description: 有一颗$n$个节点的树,每条边有一个边权 对于一个$x$ ...

  7. codeforces 1288D. Minimax Problem(二分)

    链接:https://codeforces.com/contest/1288/problem/D D. Minimax Problem 题意:给定n个数组,长度为m,从n中数组挑选两个数组,两个数组中 ...

  8. 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 ...

  9. codeforces 340C Tourist Problem

    link:http://codeforces.com/problemset/problem/340/C 开始一点也没思路,赛后看别人写的代码那么短,可是不知道怎么推出来的啊! 后来明白了. 首先考虑第 ...

随机推荐

  1. 工作5年的Java程序员,才学会阅读源码,可悲吗?

    最近一位5年开发经验的群友与我聊天 他说:最近慢慢的尝试去看spring的源码,学习spring,以前都只是会用就行了,但是越是到后面,发现只懂怎么用还不够,在面试的时候经常被问到一些开源框架的源码问 ...

  2. (四)五种IO模型

    基本概念 我们之前编写的套接字程序都是阻塞式的,其实这也是默认的形式.现在我们需要明确一些概念: 用户空间和内核空间 首先要明确,用户启动的应用程序在系统中以一个进程的形式存在,而无论对于网络数据还是 ...

  3. leetcode — remove-duplicates-from-sorted-list-ii

    /** * Source : https://oj.leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ * * * Given a ...

  4. kernel pwn 入门环境搭建

    刚开始上手kernel pwn,光环境就搭了好几天,应该是我太菜了.. 好下面进入正题,环境总共就由两部分构成,qemu和gdb.这两个最好都需要使用源码安装. 我使用的安装环境为 qemu:安装前要 ...

  5. SQL优化总结之二

    1.列优先 如图有表A和表B,对其查询时,会有如下语句: select a.*,b.* from a,b where a.id = b.a_id; 注意from 后边的表名, a.如果多表查询是完全无 ...

  6. C#使用Http的Post方式请求webservice

    webservice是以前比较流行的跨系统.跨语言.跨平台的数据交互技术.最近工作中调用Java作为服务端开放的webser,我是通过VS205生成webservice工具类的方式进行接口调用的.用这 ...

  7. AppBoxFuture(六): 前端组件化开发

      前面几篇都是在介绍结构化与非结构化的数据存储,本篇换换口味介绍一下框架是如何实现前端组件化开发的.首先得感谢Vue.ElementUI等优秀的前端开源项目,这些项目帮助作者快速实现了框架的两个前端 ...

  8. http无状态

    说http无状态,客户端请求,建立一个链接,请求完毕既会关掉连接,避免占用通道,对处理业务逻辑没有记忆功能

  9. javascript基础修炼(1)——一道十面埋伏的原型链面试题

    在基础面前,一切技巧都是浮云. 题目是这样的 要求写出控制台的输出. function Parent() { this.a = 1; this.b = [1, 2, this.a]; this.c = ...

  10. [Go] go get获取官方库被墙解决

    1.直接在github上clone对应的代码 , 地址为: https://github.com/golang/xxxxxxx.git xxxxxxx为所缺的库名  , 比如net库  text库 h ...