little difference
把一个数字分解成有限个相差不超过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的更多相关文章
- Java 堆内存与栈内存异同(Java Heap Memory vs Stack Memory Difference)
--reference Java Heap Memory vs Stack Memory Difference 在数据结构中,堆和栈可以说是两种最基础的数据结构,而Java中的栈内存空间和堆内存空间有 ...
- 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 ...
- [转载]Difference between <context:annotation-config> vs <context:component-scan>
在国外看到详细的说明一篇,非常浅显透彻.转给国内的筒子们:-) 原文标题: Spring中的<context:annotation-config>与<context:componen ...
- 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 ...
- difference between forward and sendredirect
Difference between SendRedirect and forward is one of classical interview questions asked during jav ...
- 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 ...
- MySQL: @variable vs. variable. Whats the difference?
MySQL: @variable vs. variable. Whats the difference? up vote351down votefavorite 121 In another qu ...
- 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 ...
- 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 ...
- js-FCC算法-Symmetric Difference
创建一个函数,接受两个或多个数组,返回所给数组的 对等差分(symmetric difference) (△ or ⊕)数组. 给出两个集合 (如集合 A = {1, 2, 3} 和集合 B = {2 ...
随机推荐
- Eclipse workspace被锁定
重新打开Eclipse时,提示如下: Workspace Unavailable: Workspace in use or cannot be created, choose a different ...
- Qt QPushButton 背景色
正常状态:黑底(背景色),白字(前景色),圆角,向外凸起 鼠标停留:背景和前景反色 鼠标按下:背景色变为淡蓝色,向内凹陷 ui->pushButton->setStyleSheet(&qu ...
- 7层网络以及5种Linux IO模型以及相应IO基础
一.七层网络模型 OSI是Open System Interconnection的缩写,意为开放式系统互联.国际标准化组织(ISO)制定了OSI模型,该模型定义了不同计算机互联的标准,它是一个七层的. ...
- 【nodejs代理服务器二】nodejs webpack打包配置踩坑总结
接着上篇用Nodejs开发web代理,防止web渗透.如果部署到正式环境,需要进行打包配置. 我在用webpack打包配置中遇到了几个错误,总结如下: webpack环境变量问题 https://ww ...
- c# 值传递
- Kubernetes 1.14发布:对Windows节点的生产级支持、Kubectl更新与持久本地卷通用版本已全面到来
今天,我们高兴地宣布Kubernetes 1.14版本的正式亮相,这亦是我们在2019年当中进行的首次发布!Kubernetes 1.14版本由31项增强功能组成,具体包括:10项稳定版功能,12项b ...
- shell中判断前一个命令是否执行成功
]; then echo "fail" else echo "success" fi 或者 ]; then echo "success" e ...
- HDU 6187 Destroy Walls (思维,最大生成树)
HDU 6187 Destroy Walls (思维,最大生成树) Destroy Walls *Time Limit: 8000/4000 MS (Java/Others) Memory Limit ...
- Vim使用技巧(0) -- 博主的vim配置
vim ~/.vimrc "插入模式时 光标的上下左右移动 inoremap <C-l> <Right> inoremap <C-h> <Left& ...
- vuex 随笔
vuex刷新数据消失问题: 在项目的入口页面(App.vue)里添加监听刷新事件: 或者使用插件:npm install vuex-persistedstate --save