链接一
链接二
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

思路

题目转换:
N >= gcd * (1 + 2 + ….+ k)
N在符合上面的式子下求最大的gcd。
可以从1开始枚举gcd 直到刚好大于或等于N的时候停止,最后贪心输出答案

注意细节
  1. 求(1 + 2 + … + k)的时候可能会爆 long long
  2. 可以用sqrt枚举,降低复杂度

AC

#include<bits/stdc++.h>
#define N 10006
#define ll long long
using namespace std;
ll n, k, limit;
int judge(ll x) {   //判断此时的gcd是否合适 if(limit <= x)  return 1;else    return 0;
}
int main() {
//  freopen("in.txt", "r", stdin);while (scanf("%lld%lld", &n, &k) != EOF) {limit = (1 + k) * k / 2;      if (k > 141421 || limit > n){   //特判不符合条件,limit 也可能爆long longprintf("-1\n");continue;}       if (limit == n) {   //特判相等 答案:1--k for (ll i = 1; i <= k; i++) printf("%d ", i);printf("\n");}else {ll gcd;for (ll i = 1; i <= sqrt(n); i++) { //每次找n的因子,sqrt降低复杂度,否则1e10 if (n % i == 0) {if (judge(i)) { //此时使得 gcd = n / i 最大,即为答案  gcd = n / i;break;}if (judge(n / i)) { //gcd从小找,找到不合适的就退出 gcd = i;}else {break;}}//同理也可以写成
//              if (n % i == 0) {//                  if (i >= limit) {//                      gcd = n / i;
//                      break;
//                  };
//                  if(n / i >= limit) {//                      gcd = i;
//                  }
//              } }//贪心输出答案,前K - 1项为 1*gcd到k-1*gcd ll temp = n / gcd;for(ll i = 1; i < k; i++) { //输出前K项 printf("%lld ", gcd * i);temp -= i;}printf("%lld\n", gcd * temp);   //输出最后一项}}   return 0;
}

CodeForces - 803C Maximal GCD(贪心 + 枚举)相关推荐

  1. 【Codeforces 803 C. Maximal GCD】

    C. Maximal GCD time limit per test1 second memory limit per test256 megabytes inputstandard input ou ...

  2. Maximal GCD

    Maximal GCD You are given positive integer number n. You should create such strictly increasing sequ ...

  3. 【CodeForces - 1020C】Elections (枚举投票数,贪心)

    题干: As you know, majority of students and teachers of Summer Informatics School live in Berland for ...

  4. Codeforces 1395 D. Boboniu Chats with Du(贪心枚举答案)

    传送门 题意: 思路: 先把大于m的放在b数组,小于m的放在a数组 枚举一下最终结果中用了几个b,取一个最大值即可 看代码应该能明白(有注释) 代码: int a[MAXN],b[MAXN]; ll ...

  5. codeforces数学1600day6[CodeForces - 1029C多区间交+枚举,CodeForces 992C[数学公式推导],CodeForces 992B[质因数分解+暴力枚举]]

    A - Maximal Intersection CodeForces - 1029C 题目大意:就是给你n个区间,这n个区间有公共的区间长度为x,现在叫你从这n个区间中删掉一个使得x最大化. 解题思 ...

  6. CF803C Maximal GCD

    洛谷 CF 分析 考虑从 \(k\) 个数的 \(gcd\) 入手. 设他们的 \(gcd\) 为 \(d\) .则有 \(d|n\) ,那么这 \(k\) 个数都除以 \(d\) 剩下的和即为 \( ...

  7. CodeForces 176A Trading Business 贪心

    Trading Business 题目连接: http://codeforces.com/problemset/problem/176/A Description To get money for a ...

  8. 【Codeforces】158B-Taxi(贪心,怎么贪咧)

         贪心   emmmm http://codeforces.com/contest/158/problem/B 题目大意:有四种旅客,四人一组,三人一组,两人一组,一人一组,一辆出租车最多可以 ...

  9. CodeForces - 1607D Blue-Red Permutation(贪心)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的数列,每个数字有一个颜色,如果是蓝色,每次操作则可以减一:如果是红色,每次操作则可以加一. 问有限次操作后,能否将数组变为一个长度为 nnn 的 ...

最新文章

  1. python在windows下import其他模块的注意事项
  2. 什么是Linux的原生GUI API?
  3. SgmlReader使用方法
  4. 如何用命令行给mySQL添加用户
  5. 50张图,带你认识大学各专业
  6. C语言 typedef 和 define 区别 - C语言零基础入门教程
  7. python如何用matplotlib绘图_Python绘图的多图控制(使用Matplotlib),python,利用,matplotlib...
  8. jquery的图片轮播 模板类型
  9. 使用线程池管理线程!
  10. android studio for android learning (一)
  11. 多智能体强化学习—QMIX
  12. 从0搭建一个邮件服务器(用于邮件推送以及邮件群发业务)
  13. 通过console线登录交换机
  14. Codeforces1196D2
  15. VulnHub 靶场--October
  16. MySQL中的子查询用法
  17. 提问(小白问题):为什么这里调试的时候无法输入
  18. 基于深度强化学习的智能船舶航迹跟踪控制
  19. 网络套接字------IP地址
  20. 光猫+路由器双工配置

热门文章

  1. linux下自定义dubbo的shell脚本
  2. JDBC链接oracle已经mysql的测试
  3. PHP-代码审计-变量覆盖
  4. [Python人工智能] 三十.Keras深度学习构建CNN识别阿拉伯手写文字图像
  5. 20. Valid Parentheses 有效的括号
  6. Python和单元测试那些事儿
  7. 阿里云服务器ssh连接经常断开
  8. Martix工作室考核题 —— 2019-3-8 第三题
  9. 2014\Province_C_C++_A\2 切面条
  10. PaddlePaddle训练营——公开课——AI核心技术掌握——第2章机器能“看”的现代技术