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
  1. 6 3
Output
  1. 1 2 3
Input
  1. 8 2
Output
  1. 2 6
Input
  1. 5 3
Output
  1. -1
  2.  
  3. 题意:构造一个递增的长度为k 和为n 的数列,gcd尽可能的大.
    题解:gcd 1~i 所以寻找长度为k 首项为i 等差为i 数列和为n的一个序列
    细细考虑 n应当模尽i 那么枚举n的因子 check 一下 取最大的i
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. #include<cstring>
  5. #include<algorithm>
  6. #include<set>
  7. #include<vector>
  8. #define ll __int64
  9. using namespace std;
  10. ll n,k;
  11. bool fun(ll s){
  12. if(k*(k+)*s/>n)
  13. return false;
  14. if((n-k*(k-)*s/)%s==)
  15. return true;
  16. return false;
  17. }
  18. int main()
  19. {
  20. scanf("%I64d %I64d",&n,&k);
  21. if(k>(*n/(+k)))
  22. printf("-1\n");
  23. else
  24. {
  25. ll e=;
  26. for(ll i=;i*i<=n;i++){
  27. if(n%i==&&fun(i)) e=max(e,i);
  28. if(n%i==&&fun(n/i)) e=max(e,n/i);
  29. }
  30. for(int j=; j<k; j++)
  31. printf("%I64d ",j*e);
  32. printf("%I64d\n",n-k*(k-)*e/);
  33. }
  34. return ;
  35. }
  1.  

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 53C(二分,思维|构造)

    #include<bits/stdc++.h>using namespace std;const int N=1e6+6;int x[N],y[N];int sx,sy,n;char s[ ...

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

  4. Educational Codeforces Round 20 C(math)

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

  5. Educational Codeforces Round 64 -B(贪心)

    题目链接:https://codeforces.com/contest/1156/problem/B 题意:给一段字符串,通过变换顺序使得该字符串不包含为位置上相邻且在字母表上也相邻的情况,并输出. ...

  6. Educational Codeforces Round 15 D 数学推公式

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. Educational Codeforces Round 20.C

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

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

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

随机推荐

  1. jsp 修改页面感受

    什么事情只有做过才知道. 最近在负责官网的开发,有一些页面需要和前端商量着修改,但是看到jsp那繁杂的标签和各种css,js混到一起,实在觉得jsp已经是一种落后的技术了,在修改过程中频频出现各种格式 ...

  2. [leetcode]三数之和

    三数之和 给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组. 注意:答案中不可以包含重复 ...

  3. 【转】: 塞尔达组在GDC2017演讲的文字翻译:显示的力量

      塞尔达系列推出新作的时候,美术风格都有明显变化.本作的风格比起写实,笔触轻快变化幅度大是其特征.2011年公开的技术演示中,画面风格要更加写实.最终版则更接近于卡通.5年里到底发生了什么呢? ▲2 ...

  4. 高可用Kubernetes集群-7. 部署kube-controller-manager

    九.部署kube-controller-manager kube-controller-manager是Kube-Master相关的3个服务之一,是有状态的服务,会修改集群的状态信息. 如果多个mas ...

  5. Python 内置函数介绍

    作者博文地址:http://www.cnblogs.com/spiritman/ Python Built-in Functions

  6. [C++] Solve "Cannot run program "gdb": Unknown reason" error

    In Mac OSX, The Issue Image: 1. Build the project on Eclipse successfully. 2. Run gdb on command lin ...

  7. OrderSys---Spring 计划(第一天)

    Sprint 计划会议: 目标: 1.了解需求分析书的内容 2.划分OrderSys的功能模块 3.开始制作原型 Sprint 3 Backlog细化: ID Name Est How to demo ...

  8. AJAX请求.net controller数据交互过程

    AJAX发出请求 $.ajax({ url: "/Common/CancelTaskDeal", //CommonController下的CancelTaskDeal方法 type ...

  9. 评价Win8自带输入法

    对于人机交互设计,有以下四个基本原则:从用户角度考虑.从头到尾记住用户选择.短期刺激和长期使用的好处坏处.不让用户犯简单错误.我用的最多的是我的系统自带的输入法,评价的也只能是它了. 1.从用户角度: ...

  10. html个人网页

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...