把一个数字分解成有限个相差不超过1的因子;

这里如果是2的n次幂就不可以,因为比如4,可以拆成 2,2,或者2,2,1,或者2,2,1,1,。。。所有这个不可以,没想到这个

数据是1E18,一开始想觉得都会TLE,但是其实如果拆成2个数字,要相差不超过1,可能是根号n和根号n,或者根号n和根号n+1,因此只要把这个特判一下,之后分成三个数字,最大1E6,可以直接裸跑到1e6就可以找出答案了,每一次最多循环log(n)次,时间复杂度1e6*log(n),可以做;

  1. #include<bits/stdc++.h>
  2. #define sf scanf
  3. #define pf printf
  4. #define si(a) a.size()
  5. #define pb push_back
  6. #define vi vector<int>
  7. #define scf(x) scanf("%d",&x)
  8. #define scff(x,y) scanf("%d%d",&x,&y)
  9. #define rep(i,a,n) for (ll i=a;i<n;i++)
  10. #define per(i,a,n) for (ll i=a;i>=n;i--)
  11. #define mm(x,b) memset((x),(b),sizeof(x))
  12. #define scfff(x,y,z) scanf("%d%d%d",&x,&y,&z)
  13. #define de(a) cout << #a << " = " << a << endl
  14. #define dd(a) cout << #a << " = " << a << " "
  15. typedef long long ll;
  16. using namespace std;
  17. const double eps=1e-8;
  18. const int N=2e6+2;
  19. vector<long long > v[N];
  20. int main()
  21. {
  22. freopen("little.in","r",stdin);
  23. freopen("little.out","w",stdout);
  24. ll n;
  25. cin>>n;
  26. if(n==1||n==2)
  27. {
  28. cout<<"-1";
  29. return 0;
  30. }
  31. v[0].pb(1);
  32. v[0].pb(n);
  33. ll ttt=1;
  34. ll q=ll(sqrt(n));
  35. if(n%q==0)
  36. {
  37. if(abs(n/q-q)<=1)
  38. {
  39. v[ttt].pb(2);
  40. v[ttt].pb(q);
  41. v[ttt].pb(n/q);
  42. ttt++;
  43. //cout<<"2 "<<q<<" "<<n/q<<endl;
  44. }
  45. }
  46. rep(i,2,N)
  47. {
  48. ll qq=n;
  49. if(qq%i==0||qq%(i+1)==0)
  50. {
  51. ll bits1=0,bits2=0;
  52. while(qq%i==0) {
  53. bits1++;
  54. qq/=i;
  55. }
  56. while(qq%(i+1)==0)
  57. {
  58. bits2++;
  59. qq/=(i+1);
  60. }
  61. if(i==2&&bits2==0&&qq==1)
  62. {
  63. cout<<"-1";
  64. return 0;
  65. }
  66. if(qq==1&&(bits1+bits2)!=2&&(bits1+bits2)!=1)
  67. {
  68. v[ttt].pb(bits1+bits2);
  69. //cout<<bits1+bits2;
  70. rep(j,0,bits1)
  71. v[ttt].pb(i);
  72. // pf(" %d",i);
  73. rep(j,0,bits2)
  74. v[ttt].pb(i+1);
  75. // pf(" %d",i+1);
  76. if(bits1==0)
  77. i++;
  78. ttt++;
  79. }
  80. }
  81. }
  82. cout<<ttt<<endl;
  83. rep(i,0,ttt)
  84. {
  85. ll len=si(v[i]);
  86. cout<<v[i][0];
  87. rep(j,1,len)0
  88. {
  89. pf(" %lld",v[i][j]);
  90. }
  91. cout<<endl;
  92. }
  93. return 0;
  94. }

little difference的更多相关文章

  1. Java 堆内存与栈内存异同(Java Heap Memory vs Stack Memory Difference)

    --reference Java Heap Memory vs Stack Memory Difference 在数据结构中,堆和栈可以说是两种最基础的数据结构,而Java中的栈内存空间和堆内存空间有 ...

  2. What's the difference between a stub and mock?

    I believe the biggest distinction is that a stub you have already written with predetermined behavio ...

  3. [转载]Difference between <context:annotation-config> vs <context:component-scan>

    在国外看到详细的说明一篇,非常浅显透彻.转给国内的筒子们:-) 原文标题: Spring中的<context:annotation-config>与<context:componen ...

  4. What's the difference between <b> and <strong>, <i> and <em> in HTML/XHTML? When should you use each?

    ref:http://stackoverflow.com/questions/271743/whats-the-difference-between-b-and-strong-i-and-em The ...

  5. difference between forward and sendredirect

    Difference between SendRedirect and forward is one of classical interview questions asked during jav ...

  6. Add Digits, Maximum Depth of BinaryTree, Search for a Range, Single Number,Find the Difference

    最近做的题记录下. 258. Add Digits Given a non-negative integer num, repeatedly add all its digits until the ...

  7. MySQL: @variable vs. variable. Whats the difference?

    MySQL: @variable vs. variable. Whats the difference?   up vote351down votefavorite 121 In another qu ...

  8. Distribute numbers to two “containers” and minimize their difference of sum

    it can be solved by Dynamical Programming.Here are some useful link: Tutorial and Code: http://www.c ...

  9. difference between append and appendTo

    if you need append some string to element and need set some attribute on these string at the same ti ...

  10. js-FCC算法-Symmetric Difference

    创建一个函数,接受两个或多个数组,返回所给数组的 对等差分(symmetric difference) (△ or ⊕)数组. 给出两个集合 (如集合 A = {1, 2, 3} 和集合 B = {2 ...

随机推荐

  1. python网络爬虫之爬取图片

    今天使用requests和BeautifulSoup爬取了一些图片,还是很有成就感的,注释可能有误,希望大家多提意见: 方法一:requests import requests from bs4 im ...

  2. IP地址简介及Linux网络管理工具

    IP地址简介 IP地址又叫网络地址也称逻辑地址,由32位2进制数组成,分4段每段8位,由10进制数表示,范围0~,段与段之间用点隔开采用点分十进制的表示法,在一个网络中ip地址是唯一的,IP地址最主要 ...

  3. Linux命令——column

    参考:Viewing Linux output in columns 功能 column命令把他的输入格式化多列显示.输入可以是文件,也可以是标准输入. 列优先,从左到右 显示的时候首先填满最左列,然 ...

  4. 读书笔记——《redis入门指南(第2版)》第七章 持久化

    7 持久化 在一些情况下,我们会希望Redis 在重启后能够保证数据不丢失,例如: 1·将Redis 作为数据库使用时. 2·将Redis 作为缓存服务器,有可能出现的缓存雪崩会使服务无法响应. 这时 ...

  5. 第七周作业:powerdesigner使用小结

    powerdesigner使用小结 这款软件使得开发人员为了方便进行数据库的建立以及逻辑关系的实现,而不用自己去“手写”代码,代码在数据库建模完成后可以直接的生成. 如果你电脑上安装了这款软件的话可以 ...

  6. unity和lua开发游戏常备技能

    推荐阅读:  我的CSDN  我的博客园  QQ群:704621321  我的个人博客 一.使用制作滑动列表:使用UILayout做虚拟列表 ui.list = base:findcom(" ...

  7. React 之 高阶组件的理解

    1.基本概念 高阶组件是参数为组件,返回值为新组件的函数. 2.举例说明 ① 装饰工厂模式 组件是 react 中的基本单元,组件中通常有一些逻辑(非渲染)需要复用处理.这里我们可以用高阶组件对组件内 ...

  8. React Snippets 常用记录

    官网 PropTypes ptar→ PropTypes.array.isRequired ptor→ PropTypes.object.isRequired ptsr→ PropTypes.stri ...

  9. C++重温历史

    这是一篇C#开发重新学习C++的体验文章. 作为一个C#开发为什么要重新学习C++呢?因为在C#在很多业务场景需要调用一些C++编写的COM组件,如果不了解C++,那么,很容易注定是要被C++同事忽悠 ...

  10. Vue Router 使用方法

    安装 直接下载 / CDN https://unpkg.com/vue-router/dist/vue-router.js Unpkg.com 提供了基于 NPM 的 CDN 链接.上面的链接会一直指 ...