把一个数字分解成有限个相差不超过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),可以做;

#include<bits/stdc++.h>
#define sf scanf
#define pf printf
#define si(a) a.size()
#define pb push_back
#define vi vector<int>
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=a;i>=n;i--)
#define mm(x,b) memset((x),(b),sizeof(x))
#define scfff(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
typedef long long ll;
using namespace std;
const double eps=1e-8;
const int N=2e6+2;
vector<long long > v[N];
int main()
{
freopen("little.in","r",stdin);
freopen("little.out","w",stdout);
ll n;
cin>>n; if(n==1||n==2)
{
cout<<"-1";
return 0;
}
v[0].pb(1);
v[0].pb(n);
ll ttt=1;
ll q=ll(sqrt(n)); if(n%q==0)
{
if(abs(n/q-q)<=1)
{
v[ttt].pb(2);
v[ttt].pb(q);
v[ttt].pb(n/q);
ttt++;
//cout<<"2 "<<q<<" "<<n/q<<endl;
}
}
rep(i,2,N)
{
ll qq=n;
if(qq%i==0||qq%(i+1)==0)
{
ll bits1=0,bits2=0;
while(qq%i==0) {
bits1++;
qq/=i;
}
while(qq%(i+1)==0)
{
bits2++;
qq/=(i+1);
}
if(i==2&&bits2==0&&qq==1)
{
cout<<"-1";
return 0;
}
if(qq==1&&(bits1+bits2)!=2&&(bits1+bits2)!=1)
{ v[ttt].pb(bits1+bits2);
//cout<<bits1+bits2;
rep(j,0,bits1)
v[ttt].pb(i);
// pf(" %d",i);
rep(j,0,bits2)
v[ttt].pb(i+1);
// pf(" %d",i+1);
if(bits1==0)
i++;
ttt++;
}
}
}
cout<<ttt<<endl;
rep(i,0,ttt)
{
ll len=si(v[i]);
cout<<v[i][0]; rep(j,1,len)0
{
pf(" %lld",v[i][j]);
}
cout<<endl;
}
return 0;
}

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. oracle的LAST_DAY()函数

    转自:https://blog.csdn.net/u012581453/article/details/53727936 LAST_DAY LAST_DAY函数返回指定日期对应月份的最后一天. 获取当 ...

  2. flask-sqlalchemy使用及数据迁移

    flask-sqlalchemy是flask框架在sqlalchemy基础上改造的一个orm框架 现在有两个实体Article文章和Category分类 一个分类下可能有多篇文章 相关示例: 项目相关 ...

  3. springboot学习入门简易版二---springboot2.0项目创建

    2 springboot项目创建(5) 环境要求:jdk1.8+ 项目结构: 2.1创建maven工程 Group id :com.springbootdemo Artifact id: spring ...

  4. nginx的proxy模块详解以及参数

    文章来源 运维公会:nginx的proxy模块详解以及参数 使用nginx配置代理的时候,肯定是要用到http_proxy模块.这个模块也是在安装nginx的时候默认安装.它的作用就是将请求转发到相应 ...

  5. 软硬RAID 和 不常见的RAID

    若转载请于明显处标明出处:http://www.cnblogs.com/kelamoyujuzhen/p/5561809.html 为啥子引入RAID? 存储最现实的两个问题:速度.容量 001——计 ...

  6. 助教培训总结——熟练掌握GitHub及Git的使用方法

    一.Git 命令的理解和使用 1.使用git前需要建立一个本地仓库,用Git GUI Here的话就可以直接选择Create New Repository.Git Bash Here输入 命令git ...

  7. java容器一:Collection概述

    Collection概览 java容器有两类,第一类是Collection,存储的是对象的集合:第二类是Map,存储的是键值对(两个对象以及它们之间的对应关系)的集合 Collection接口下面有三 ...

  8. 锁、threading.local、线程池

    一.锁 Lock(1次放1个) 什么时候用到锁: 线程安全,多线程操作时,内部会让所有线程排队处理.如:list.dict.queue 线程不安全, import threading import t ...

  9. eclipse等编辑器选中列快编辑的方法

    一.eclipse 1.首先按alt+shift+a,开启块选择模式 2.使用鼠标进行块选择 3.再次按Alt+Shift+a即可关闭块选择模式 二.EditPlus 1.菜单:编辑 -> 选择 ...

  10. 用CSS 实现 浮动元素的 水平居中

    问题描述: 基本的html结构: <div> <!-- <span>1</span> <span>2</span> <span& ...