题目: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. React 中的this.setState

    在react中如何修改state中的数据     第一种写法:this.setState()         参数1:对象 需要修改的数据         参数2:回调 this.setState是一 ...

  2. 【Zara原创】SqlSugar4轻量级ORM框架的使用指南

    前言:sqlSugar出生已经有3年之久了,从1.0到现在的4.x的版本,为了以后方便使用SqlSugar,所以特意花了2个小时来叙述它. 关于SqlSugar 性能:性能最好的ORM之一,具有超越D ...

  3. Vue生命周期详解

    Vue所有的生命周期钩子自动绑定在this上下文到实例中,因此你可以访问数据,对属性和方法进行运算.这意味着你不能使用箭头函数来定义一个生命周期方法.这是因为箭头函数绑定了父上下文,因此this与你期 ...

  4. Eureka介绍

    1.  Eureka是什么 Eureka是一个基于REST的服务,主要用于AWS云中的定位服务,以实现中间层服务器的负载平衡和故障转移 在 Spring Cloud 微服务架构中通常用作注册中心 我们 ...

  5. Solr 08 - 在Solr Web管理页面中查询索引数据 (Solr中各类查询参数的使用方法)

    目录 1 Solr管理页面的查询入口 2 Solr查询输入框简介 3 Solr管理页面的查询方案 1 Solr管理页面的查询入口 选中需要查询的SolrCore, 然后在菜单栏选择[Query]: 2 ...

  6. replugin插件化,插件转场动画失效的问题解决

    说明 随着应用功能的丰富,Android程序的安装包也逐渐变大,这成为应用程序现有框架下难以摆脱的瓶颈.所以引入了rePlugin插件化框架,将应用按功能拆分为插件,以此减小apk的大小并同时增加应用 ...

  7. 带着新人学springboot的应用04(springboot+mybatis+redis 完)

    对于缓存也说了比较多了,大家对下图这一堆配置类现在应该有些很粗略的认识了(因为我也就很粗略的认识了一下,哈哈!),咳,那么我们怎么切换这个缓存呢?(就是不用springboot提供的默认的Simple ...

  8. 前端笔记之jQuery(上)加载函数的区别&对象&操作HTML/CSS&动画&选择器

    一.jQuery简介 1.0 JavaScript编程比较恶心的地方 恶心1:选择元素麻烦,全线兼容的方法只有getElementById()和getElementsByTagName()两个.其他的 ...

  9. centos 7 linux系统安装 mysql5.7.17(glibc版)

    前言:经过一天半的折腾,终于把 mysql 5.7.17 版本安装上了 centos 7 系统上,把能参考的博客几乎都看了一遍,终于发现这些细节问题,然而翻了无数的文章,基本上都没有提到这些,所以小生 ...

  10. leetcode — surrounded-regions

    import java.util.Arrays; import java.util.Stack; /** * Source : https://oj.leetcode.com/problems/sur ...