C. Maximal GCD
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a1, a2, ..., ak, that their sum is equal to n and greatest common divisor is maximal.

Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.

If there is no possible sequence then output -1.

Input

The first line consists of two numbers n and k (1 ≤ n, k ≤ 1010).

Output

If the answer exists then output k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.

Examples
input
6 3
output
1 2 3
input
8 2
output
2 6
input
5 3
output
-1

题意:输出一个k项数列使其满足:

1.各项之和为n    2.单增      3.最大公约数最大化。

思路:枚举n的因子q,找到满足n/q>=k*(k+1)/2 的最大q, 输出数列

PS:这题坑点挺多的。。比如数据范围  n,k 都是1e10 特判要考虑到这点。

代码:

 #include<stdio.h>
 #include<iostream>
 #include<algorithm>
 #include<string.h>
 #include<math.h>
 #include<stdlib.h>
 #include<ctype.h>
 #include<stack>
 #include<queue>
 #include<map>
 #include<set>
 #include<vector>
 #define ll long long
 #define  db double
 using namespace std;
 ;
 ;
 int main()
 {
     ll n,k;
     db s=sqrt(2.0);
     scanf("%lld%lld",&n,&k);
     ll ans=n;
     )/) {//必须要判断k的值,否则会溢出。
         puts("-1");
         ;
     }
     ll ma=;
     ;i<=sqrt(n);i++){
         &&n/i>=k*(k+)/){ //i,n/i都可能是最大因子
             ma=max<ll>(ma,i);
             )/) ma=max<ll>(ma,n/i);
         }
     }
     ;i<k;i++){
         printf("%lld ",i*ma);
         ans-=i*ma;
     }
     printf("%lld\n",ans);

 }

Educational Codeforces Round 20.C的更多相关文章

  1. Educational Codeforces Round 20

    Educational Codeforces Round 20  A. Maximal Binary Matrix 直接从上到下从左到右填,注意只剩一个要填的位置的情况 view code //#pr ...

  2. Educational Codeforces Round 20 D. Magazine Ad

    The main city magazine offers its readers an opportunity to publish their ads. The format of the ad ...

  3. Educational Codeforces Round 20 C(math)

    題目鏈接: http://codeforces.com/problemset/problem/803/C 題意: 給出兩個數n, k, 將n拆分成k個數的和,要求這k個數是嚴格遞增的,並且這k個數的g ...

  4. Educational Codeforces Round 20 C 数学/贪心/构造

    C. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard input ...

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

  6. Educational Codeforces Round 20 B. Distances to Zero

    B. Distances to Zero time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. Educational Codeforces Round 20 A. Maximal Binary Matrix

    A. Maximal Binary Matrix time limit per test 1 second memory limit per test 256 megabytes input stan ...

  8. Educational Codeforces Round 20 E - Roma and Poker(dp)

    传送门 题意 Roma在玩一个游戏,一共玩了n局,赢则bourle+1,输则bourle-1,Roma将会在以下情况中退出 1.他赢了k个bourle 2.他输了k个bourle 现在给出一个字符串 ...

  9. Educational Codeforces Round 20 B

    Description You are given the array of integer numbers a0, a1, ..., an - 1. For each element find th ...

随机推荐

  1. Ubuntu 挂载硬盘分区

    1.先查看当前硬盘分区状态,命令sudo fdisk -l 大致如下:设备 启动 Start 末尾 扇区 Size Id 类型/dev/sda1 2048 206847 204800 100M 7 H ...

  2. 张小龙的野心:用小程序重构web|小程序好处及可能的不足

    一:张小龙的野心:用小程序重构web 一 很多年以前,张小龙写了一款软件:Foxmail. 这款软件当年有数百万用户,这是一个相当庞大的量,因为彼时网民也只有千万当量级的规模. 我是一个非常忠实的用户 ...

  3. 关于DB2死锁处理

    昨天在修改字段类型的时候引起了死锁,我一般会使用REORG命令处理,在控制中心下 只需要执行 REORG TABLE TABLENAME  命令就可以, 但是在 RazorSQL 下执行此命令会报缺失 ...

  4. Maven学习(五)

    使用Maven构建多模块项目 一般的web项目构成: 建立解决方案目录parent 首先使用命令进入到我们需要建立maven项目的目录: mvn archetype:generate -DgroupI ...

  5. zabbix监控redis

    导入监控模板 点击[configuration]-->[templates]-->[import],导入xml监控模板. 配置客户端key 在被监控的主机上,新建/etc/zabbix/z ...

  6. Grid search in the tidyverse

    @drsimonj here to share a tidyverse method of grid search for optimizing a model's hyperparameters. ...

  7. SDN学习之实现环路通信

    在对OpenFlow协议有了一定了解以后,开始尝试如何通过Ryu控制器实现网络中的通信.根据协议,我们知道,当数据信息首次传输到交换机时,由于交换机不存在该数据信息所对应的流表,因此,会触发Packe ...

  8. 源码分析 Large-Margin Softmax Loss for Convolutional Neural Networks

    作者在Caffe中引入了一个新层,一般情况在Caffe中引入一个新层需要修改caffe.proto,添加该层头文件*.hpp,CPU实现*.cpp,GPU实现*.cu,代码结果如下图所示: caffe ...

  9. JavaScript 循环性能比较

    有一句话叫做 没有什么事是一个循环解决不了的,如果真有,那就再来一个循环. 循环的种类有很多 正向for循环,逆向for循环,while循环,for-in循环(理论上性能最差),for-each循环, ...

  10. spring-boot+mybatis开发实战:如何在spring-boot中使用myabtis持久层框架

    前言: 本项目基于maven构建,使用mybatis-spring-boot作为spring-boot项目的持久层框架 spring-boot中使用mybatis持久层框架与原spring项目使用方式 ...