传送:http://codeforces.com/gym/101612

题意:给定一个数n(<=1e18),将n分解为若干个数的成绩。要求这些数两两之间的差值不能大于1。

分析:

若n==2^k,则答案一定是-1。

然后,考虑若n==a^k,枚举k,二分求a。若n==a^x*(a+1)^y,枚举x,y,二分求解a。

注意:两数相乘可能>1e18,特判。

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<pair<ll,ll>,ll> plll;
const int maxn=1e6+;
const ll inf=1e18+1e6;
ll n;
vector<pll> g1;
vector<plll> g2;
ll mul(ll a,ll b){
if (a>=1.0*inf/b) return inf;
else return a*b;
}
ll _pow(ll a,ll b){
ll res=,base=a;
while (b){
if (b&) res=mul(res,base);
base=mul(base,base);
b>>=;
}
return res;
}
ll solve(int k){
ll l=,r=n,ans,mid;
while (l<=r){
mid=(l+r)>>;
ll tmp=_pow(mid,k);
if (tmp==n) return mid;
if (tmp<n) l=mid+; else r=mid-;
}
return ;
}
ll solve2(int x,int y){
ll l=,r=n,ans,mid;
while (l<=r){
mid=(l+r)>>;
ll tmp=_pow(mid,x),tmp2=_pow(mid+,y);
if (mul(tmp,tmp2)==n) return mid;
if (mul(tmp,tmp2)<n) l=mid+; else r=mid-;
}
return ;
}
int main(){
//freopen("little.in","r",stdin);freopen("little.out","w",stdout);
ios::sync_with_stdio(false);
cin >> n;
if (n==(n&(-n))) return cout << - << endl,;
g1.clear(); g2.clear();
ll num=;
// a^k
for(int i=;i<=;i++){
ll a=solve(i);
if (_pow(a,i)==n){
g1.push_back({i,a});
}
}
// a^x * (a+1)^y
for(int i=;i<=;i++){
for (int j=;j<=;j++){
ll a=solve2(i,j);
ll tmp=_pow(a,i),tmp2=_pow(a+,j);
if (mul(tmp,tmp2)==n){
g2.push_back({{i,j},a});
}
}
}
cout << g1.size()+g2.size() << endl;
for (auto i:g1){
ll tmp=i.first;
cout << tmp;
for (int j=;j<tmp;j++) cout << " " << i.second;
cout << endl;
}
for (auto i:g2){
ll tmp=i.first.first+i.first.second;
cout << tmp;
tmp=i.first.first;
for (int j=;j<tmp;j++) cout << " " << i.second;
tmp=i.first.second;
for (int j=;j<tmp;j++) cout << " " << i.second+;
cout << endl;
}
return ;
}

Codeforces gym101612 L.Little Difference(枚举+二分)的更多相关文章

  1. Codeforces 626E Simple Skewness(暴力枚举+二分)

    E. Simple Skewness time limit per test:3 seconds memory limit per test:256 megabytes input:standard ...

  2. Codeforces C. Maximum Value(枚举二分)

    题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. CSU OJ PID=1514: Packs 超大背包问题,折半枚举+二分查找。

    1514: Packs Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 61  Solved: 4[Submit][Status][Web Board] ...

  4. CodeForces 1117C Magic Ship (循环节+二分答案)

    <题目链接> 题目大意: 给定起点和终点,某艘船想从起点走到终点,但是海面上会周期性的刮风,船在任何时候都能够向四个方向走,或者选择不走,船的真正行走路线是船的行走和风的走向叠加的,求船从 ...

  5. HDU4430 Yukari's Birthday(枚举+二分)

    Yukari's Birthday  HDU4430 就是枚举+二分: 注意处理怎样判断溢出...(因为题目只要10^12) 先前还以为要用到快速幂和等比数列的快速求和(但肯定会超__int64) 而 ...

  6. POJ 2549 Sumsets(折半枚举+二分)

    Sumsets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11946   Accepted: 3299 Descript ...

  7. 4 Values whose Sum is 0(枚举+二分)

    The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute ...

  8. Codeforces Round #379 (Div. 2) C. Anton and Making Potions 枚举+二分

    C. Anton and Making Potions 题目连接: http://codeforces.com/contest/734/problem/C Description Anton is p ...

  9. Codeforces H. Prime Gift(折半枚举二分)

    题目描述: Prime Gift time limit per test 3.5 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. 导入CA证书报错 keytool error: java.lang.Exception: Input not an X.509 certificate

    导入CA证书报错: keytool error: java.lang.Exception: Input not an X.509 certificate 如果你的CA证书是如下格式的: -----BE ...

  2. AttributeError: type object 'testClass' has no attribute 'testMothod'

    点击"Unittest for test_post_API.testClass"按钮,点击”Edit configuration...“,弹出对话框Run/Debug config ...

  3. 图解TCP/IP(一)

    IP(Internet Protocol) IP/ICMP -数据链路层的主要作用是在互连同一种数据链路的节点之间进行包传递.而一旦跨越多种数据链路,就需要借助网络层. -配备IP的设备,但是不进行路 ...

  4. 如何制作chm文件

    本文介绍如何从一个包中的docs文档生成一个chm文档. 1,准备软件Easy CHM 这个网上有下载,下载后安装,至于怎么使用,等下再介绍.安装之后如下图. 2,准备文件 比如我这里下载了一个cxf ...

  5. mmm和mmma的区别

    m:编译整个安卓系统 makes from the top of the tree mm:编译当前目录下的模块,当前目录下需要有Android.mk这个makefile文件,否则就往上找最近的Andr ...

  6. platform总线,设备,驱动的注册

    linux设备驱动归纳总结(九):1.platform总线的设备和驱动 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...

  7. 天使投资、A轮、B轮、C轮

    一般是这样划分的. A轮融资:公司产品有了成熟模样,开始正常运作一段时间并有完整详细的商业及盈利模式,在行业内拥有一定地位和口碑.公司可能依旧处于亏损状态.资金来源一般是专业的风险投资机构(VC).投 ...

  8. C++的重载流输出运算符

    // 下列代码输出什么?#include <iostream>#include <string>// typedef basic_ostream<char> ost ...

  9. 笔记:认识 head 标签 待 更新中……

    文档的头部描述了文档的各种属性和信息,包括文档的标题等.绝大多数文档头部包含的数据都不会真正作为内容显示给读者. 下面这些标签可用在 head 部分: <head> <title&g ...

  10. 基于VRML的虚拟校园漫游系统

    最近学习VRML的开发,在CSDN网上搜索到一个基于VRML的虚拟校园漫游系统.感觉很不错. 浏览效果如下: