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 ...
随机推荐
- 碰撞器Colider 触发器
碰撞器可以让所依附的游戏物件对其他碰撞体产生碰撞行为(其他游戏物体必须具有Rigidbody组件) 对于不规则形状的物体,通常使用组合式碰撞体而不是网格碰撞器,以为网格碰撞器以模型的网格为基础,更为复 ...
- 十三、细说NULL导致的神坑,让人防不胜防
当数据的值为NULL的时候,可能出现各种意想不到的效果,让人防不胜防,我们来看看NULL导致的各种神坑,如何避免? 一.比较运算符中使用NULL 任何值和NULL使用运算符(>.<.> ...
- 一个 Git 分支协作模式的进化故事
从不用版本管理到使用 Git 分支管理的故事,也就是从这个时候开始的... 某公司只有一个程序员,一开始并没有版本管理的概念.项目开发只有一个人在参与,所以也没用版本管理工具. 后来,老板又招了两个程 ...
- 脚本shell
vim删除以#,空格开头的行 1,删除以#号开头的行: :g/^#/d :%s/^#.*\n 2,删除以空格开头的行: :g/^\s/d “\s代表空格” :%s/^ ...
- Codeforces Round #510 (Div. 2) C. Array Product
题目 题意: 给你n个数,有两种操作,操作1是把第i个位置的数删去, 操作2 是把 a[ j ]= a[ i ]* a[ j ],把a[ i ]删去 .n-1个操作以后,只剩1个数,要使这个数最大 . ...
- Socket实现client和server端通信(Java)(转)
转自: https://blog.csdn.net/yayun0516/article/details/50819147 https://www.jianshu.com/p/2d4f223f1462 ...
- php多版本配置
需求分析: 需要在一台装有php5.4的测试服务器跑的上php7.2.x的项目 安装phpenv(php版本控制) $ sudo yum install git $ mkdir -p repos/gi ...
- Android adb的一些用法
adb查看包名/Activity名 adb shell "logcat | grep START" adb shell dumpsys activity | find “mFocu ...
- CQOI2005 三角形面积并 和 POJ1177 Picture
1845: [Cqoi2005] 三角形面积并 Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 1664 Solved: 443[Submit][Stat ...
- c语言数组越界的避免方法
1.尽量显式地指定数组的边界 #define MAX 10 - int a[MAX]={1,2,3,4,5,6,7,8,9,10}; 在 C99 标准中,还允许我们使用单个指示符为数组的两段" ...