把一个数字分解成有限个相差不超过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. cocos动画没有cc.Sprite.spriteFrame属性

    对于新人来说总是有那么多的坑等着你. 新建动画节点的时候千万别[新建空节点]!!! 上面这个就是新建了空的节点,导致没有cc.Sprite.spriteFrame属性. 正确姿势: 粗略试了一下除了空 ...

  2. Python 一些内置函数的总结~~~~

    1. type() 两种用法 a. 当传入参数为一个时,返回值为参数的类型 b. 当传入参数为三个时,type(name, bases, dict) name: 类名 bases: 继承父类的元组,可 ...

  3. 用ffserver实现rtsp服务器的实验笔记

    参考:https://blog.csdn.net/hoyjam1/article/details/51281679 建议配置文件:/etc/config/ffserver.conf Port 1053 ...

  4. {RuntimeError} An attempt has been made to start a new process before the current process has finished its bootstrapping phase.This probably means that you are not using fork to start your child...

    加载数据时出现报错: RuntimeError:         An attempt has been made to start a new process before the        c ...

  5. C#开发Office程序

    标题:Office 解决方案开发概述 (VSTO) 地址:https://docs.microsoft.com/zh-cn/visualstudio/vsto/office-solutions-dev ...

  6. Linux网络编程综合运用之MiniFtp实现(七)

    上节中实现了配置文件的解析,这节来实现用户登录的验证,首先用客户端来登录vsftpd来演示登录的过程: 接着再连接miniftpd,来看下目前的效果: 接下来实现它,与协议相关的模块都是在ftppro ...

  7. Mybatis3.1-[tp-30-31]-select_resultMap_关联查询_级联属性封装结果__association定义关联对象封装规则

    笔记要点 出错分析与总结 在全局配置中,映射dao包下的全部: <mapper> <package name="com.dao"/> </mapper ...

  8. archlinux 使用 postgresql

    一.安装与初始化 1.初始化数据目录 默认安装后已创建 postgres 系统用户 切换到 postgres 用户 $ sudo -iu postgres # Or su - postgres for ...

  9. Java原子类--AtomicReference

    转载请注明出处:http://www.cnblogs.com/skywang12345/p/3514623.html AtomicReference介绍和函数列表 AtomicReference是作用 ...

  10. UVALive-7040-Color(容斥原理)

    链接: https://vjudge.net/problem/UVALive-7040 题意: Recently, Mr. Big recieved n owers from his fans. He ...