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 ...
随机推荐
- python网络爬虫之爬取图片
今天使用requests和BeautifulSoup爬取了一些图片,还是很有成就感的,注释可能有误,希望大家多提意见: 方法一:requests import requests from bs4 im ...
- IP地址简介及Linux网络管理工具
IP地址简介 IP地址又叫网络地址也称逻辑地址,由32位2进制数组成,分4段每段8位,由10进制数表示,范围0~,段与段之间用点隔开采用点分十进制的表示法,在一个网络中ip地址是唯一的,IP地址最主要 ...
- Linux命令——column
参考:Viewing Linux output in columns 功能 column命令把他的输入格式化多列显示.输入可以是文件,也可以是标准输入. 列优先,从左到右 显示的时候首先填满最左列,然 ...
- 读书笔记——《redis入门指南(第2版)》第七章 持久化
7 持久化 在一些情况下,我们会希望Redis 在重启后能够保证数据不丢失,例如: 1·将Redis 作为数据库使用时. 2·将Redis 作为缓存服务器,有可能出现的缓存雪崩会使服务无法响应. 这时 ...
- 第七周作业:powerdesigner使用小结
powerdesigner使用小结 这款软件使得开发人员为了方便进行数据库的建立以及逻辑关系的实现,而不用自己去“手写”代码,代码在数据库建模完成后可以直接的生成. 如果你电脑上安装了这款软件的话可以 ...
- unity和lua开发游戏常备技能
推荐阅读: 我的CSDN 我的博客园 QQ群:704621321 我的个人博客 一.使用制作滑动列表:使用UILayout做虚拟列表 ui.list = base:findcom(" ...
- React 之 高阶组件的理解
1.基本概念 高阶组件是参数为组件,返回值为新组件的函数. 2.举例说明 ① 装饰工厂模式 组件是 react 中的基本单元,组件中通常有一些逻辑(非渲染)需要复用处理.这里我们可以用高阶组件对组件内 ...
- React Snippets 常用记录
官网 PropTypes ptar→ PropTypes.array.isRequired ptor→ PropTypes.object.isRequired ptsr→ PropTypes.stri ...
- C++重温历史
这是一篇C#开发重新学习C++的体验文章. 作为一个C#开发为什么要重新学习C++呢?因为在C#在很多业务场景需要调用一些C++编写的COM组件,如果不了解C++,那么,很容易注定是要被C++同事忽悠 ...
- Vue Router 使用方法
安装 直接下载 / CDN https://unpkg.com/vue-router/dist/vue-router.js Unpkg.com 提供了基于 NPM 的 CDN 链接.上面的链接会一直指 ...