题目: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. scala的input

    获取用户输入的信息,一般使用 input 函数,但是 scala 里面是没有 input 这个方法的,为了获取控制台的输入操作, scala 定义的方法为: val Inputcontent = Co ...

  2. Python内置函数(57)——setattr

    英文文档: setattr(object, name, value) This is the counterpart of getattr(). The arguments are an object ...

  3. 12.Flask-Restful

    定义Restful的视图 安装:pip install flask-restful 如果使用Flask-restful,那么定义视图函数的时候,就要继承flask_restful.Resourse类, ...

  4. 前端基本知识(二):JS的原型链的理解

    之前一直对于前端的基本知识不是了解很详细,基本功不扎实,但是前端开发中的基本知识才是以后职业发展的根基,虽然自己总是以一种实践是检验真理的唯一标准,写代码实践项目才是唯一,但是经常遇到知道怎么去解决这 ...

  5. JAVA内存分配与回收策略

    对象的内存分配,大方向上讲,就是在堆上分配,对象主要分配在新生代的Eden区上,如果启动了本地线程分配缓冲,将按线程优先在TLAB上分配.少数情况下也可能会直接分配在老年代中,分配规则并不是百分百固定 ...

  6. 【ASP.NET Core快速入门】(十)Cookie-based认证实现

    准备工作 新建MVC项目,然后用VSCode打开 dotnet new mvc --name MvcCookieAuthSample 在Controllers文件夹下新建AdminController ...

  7. leetcode — subsets-ii

    import java.util.ArrayList; import java.util.Arrays; import java.util.List; /** * Source : https://o ...

  8. [八]JavaIO之FileInputStream 与 FileOutputStream

    接下来介绍 FileInputStream  和 FileOutputStream 现在看名字应该可以看得出来: 他就是从一个文件中读取数据 或者将数据写入到一个文件中 FileInputStream ...

  9. oracle数据库密码过期修改注意事项

    近期的工作中,因数据库密码临近过期,需要进行修改,因对oracle数据库底层结构不了解,导致安装网上的教程操作是出现一些问题,特记录下来 传统的修改语句为 输入:win+R进入cmd  输入sqlpl ...

  10. Tomcat多实例部署

    前言 以前总是采用很Low的方式太同一台服务器上部署多个Web应用,步骤是这样的:Copy Tomcat目录-->更改conf/server.xml三个端口号----->部署war包--- ...