枚举。

枚举$gcd$,然后计算剩下的那个数能不能分成$k$个递增的数。

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <string>
  5. #include <cmath>
  6. #include <queue>
  7. #include <stack>
  8. #include <vector>
  9. #include <map>
  10. #include <set>
  11. #include <algorithm>
  12. using namespace std;
  13.  
  14. long long b[100010];
  15. long long ans[200010];
  16. int sz;
  17. long long n,k;
  18.  
  19. void init()
  20. {
  21. for(long long i=1;i*i<=n;i++)
  22. {
  23. if(n%i!=0) continue;
  24. b[sz++] =i;
  25. if(i!=n/i) b[sz++] =n/i;
  26. }
  27. }
  28.  
  29. int main()
  30. {
  31. scanf("%lld%lld",&n,&k);
  32. init();
  33.  
  34. sort(b,b+sz);
  35.  
  36. if(k>200000)
  37. {
  38. printf("-1\n");
  39. return 0;
  40. }
  41.  
  42. int suc=0;
  43. for(int i=sz-1;i>=0;i--)
  44. {
  45. long long sum = n/b[i];
  46. long long p = (1+k)*k/2;
  47. if(p>sum) continue;
  48.  
  49. for(int j=1;j<=k;j++)
  50. {
  51. ans[j] = j;
  52. sum = sum-ans[j];
  53. }
  54. ans[k]+=sum;
  55.  
  56. for(int j=1;j<=k;j++)
  57. {
  58. ans[j]=ans[j]*b[i];
  59. }
  60.  
  61. suc=1;
  62. break;
  63. }
  64.  
  65. if(suc==0)
  66. {
  67. printf("-1\n");
  68. }
  69. else
  70. {
  71. for(long long i=1;i<=k;i++)
  72. {
  73. printf("%lld",ans[i]);
  74. if(i<k) printf(" ");
  75. else printf("\n");
  76. }
  77. }
  78.  
  79. return 0;
  80. }

CodeFoorces 803C Maximal GCD的更多相关文章

  1. codeforces 803C Maximal GCD(GCD数学)

    Maximal GCD 题目链接:http://codeforces.com/contest/803/problem/C 题目大意: 给你n,k(1<=n,k<=1e10). 要你输出k个 ...

  2. Codeforces 803C. Maximal GCD 二分

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

  3. CodeForces - 803C Maximal GCD 【构造】

    You are given positive integer number n. You should create such strictly increasing sequence of k po ...

  4. Codeforces 803C. Maximal GCD

    题目链接:http://codeforces.com/contest/803/problem/C 中了若干trick之后才过... k个数的严格递增序列最小权值和就是${n*(n+1)/2}$,枚举这 ...

  5. AC日记——Maximal GCD codeforces 803c

    803C - Maximal GCD 思路: 最大的公约数是n的因数: 然后看范围k<=10^10; 单是答案都会超时: 但是,仔细读题会发现,n必须不小于k*(k+1)/2: 所以,当k不小于 ...

  6. Maximal GCD CodeForces - 803C (数论+思维优化)

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

  7. CodeForce-803C Maximal GCD(贪心数学)

    Maximal GCD CodeForces - 803C 现在给定一个正整数 n.你需要找到 k 个严格递增的正整数 a1, a2, ..., ak,满足他们的和等于 n 并且他们的最大公因数尽量大 ...

  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. Codeforces H. Maximal GCD(贪心)

    题目描述: H. Maximal GCD time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. MakeDown的使用

    Makedown的使用 之前有用博客园来写博客,但是因为它的界面不好看,所以中途就放弃了.后来也使用过"有道云笔记",发现其写的笔记的界面很简洁工整.有道云笔记的书写原理和Make ...

  2. HDU 3507 单调队列 斜率优化

    斜率优化的模板题 给出n个数以及M,你可以将这些数划分成几个区间,每个区间的值是里面数的和的平方+M,问所有区间值总和最小是多少. 如果不考虑平方,那么我们显然可以使用队列维护单调性,优化DP的线性方 ...

  3. Redis实战(五)CentOS 7上搭建Redis集群

    高可用Redis(十二):Redis Cluster https://www.cnblogs.com/renpingsheng/p/9862485.html https://www.cnblogs.c ...

  4. 配置kernel的log buf大小(如果kmsg log被覆盖)

    如果在打印kmsg log时发现log被覆盖,log 的buf不够大可以使用默认配置调buf: defconfig CONFIG_LOG_BUF_SHIFT=20  (默认是17  2的17次方)   ...

  5. juery中循环遍历json数组

    var dataList=[]; var stock0={stockcode:"007758",stockname:"商业政7",state:"1&q ...

  6. 【BubbleCup X】D. Exploration plan

    这个题首先一眼能看出二分答案…… 毕竟连可爱的边界都给你了. 下面就是怎么check 首先预处理跑一遍floyed,预处理出最短路. 用网络流判断能否达到即可. #include<bits/st ...

  7. 读书笔记 effective c++ Item 3 在任何可能的时候使用 const

    Const可以修饰什么?   Const 关键字是万能的,在类外部,你可以用它修饰全局的或者命名空间范围内的常量,也可以用它来修饰文件,函数和块作用域的静态常量.在类内部,你可以使用它来声明静态或者非 ...

  8. spring中的任务调度Quartz

    Spring 整合 Quartz 任务调度 主要有两种方式. Quartz的官网:http://www.quartz-scheduler.org/ 这两种只是一些配置文件简单配置就OK了,但是根本无法 ...

  9. linux下rz,sz安装

    1.sz rz yum安装 yum install lrzsz

  10. 手游研发CJ抱大腿指南

    文摘要:CJ来了,又是一年一度的游戏圈盛事,随着手游行业的迅速崛起,今年CJ上,手游研发商以及发行商必定成为焦点.由于门槛低.市场热.前景好等因素的影响,国内一下子蹦出一大堆手游研发团队.很幸运(或者 ...