传送: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. spring学习十九 常用注解

    1. @Component 创建类对象,相当于配置<bean/>2. @Service 与@Component 功能相同. 2.1 写在 ServiceImpl 类上.3. @Reposi ...

  2. 微信小程序开发工具常用快捷键

    格式调整 Ctrl+S:保存文件 Ctrl+[, Ctrl+]:代码行缩进 Ctrl+Shift+[, Ctrl+Shift+]:折叠打开代码块 Ctrl+C Ctrl+V:复制粘贴,如果没有选中任何 ...

  3. 求先序排列(NOIP2001&NOIP水题测试(2017082301))

    题目链接:求先序排列 这道题讲白了,就是数的构造,然后遍历. 思路大致是这样: 我们先通过后序遍历,找到当前区间的根,然后在中序遍历中找到根对应的下标,然后就可以分出左右子树,建立当前根与左右子树根的 ...

  4. raiDrive添加坚果云

    把坚果云网盘映射到本地. 使用raidrive 中webDAV添加坚果云. 1.登录自己的坚果云网页版,点“安全选项”,右侧有第三方应用管理,生成密码,按照示例填入第三方应用即可. 2.注意:暂时此处 ...

  5. Mysql导入excel数据,解决某些特殊字符乱码问题

    问题 做项目需要从excel表格导入到mysql的数据库表中,excel表格中的“规格”字段的“×”符号导入数据库表中,会出现部分数据的“×”这个符号会乱码,成“?”的形式. 解决方法 打开excel ...

  6. 蓝绿部署、红黑部署、AB测试、灰度发布、金丝雀发布、滚动发布的概念与区别(转)

    出处:https://www.baidu.com/link?url=QjboallwNm_jxcL3fHG57wEakiBfAs_3-TChTGu1eBXstlHEsGBc-NDA7AKTqsiroB ...

  7. SQL语句之奇形怪状的冷门函数

    lag() over() ) OVER(ORDER BY C.column) FROM Table C; 第一条记录已经无法再取前一条记录,所以LAG()函数返回空. SQL为意思如下. LAG(C. ...

  8. c#中数组array和list在函数间传递 转置

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  9. VMware 14 tools位置;

    安装后默认位置: CD读入 然后,启动虚拟机. 1.创建挂载点 mkdir /mnt/cdrom 2.挂在光驱 mount /dev/cdrom /mnt/cdrom(我的这句无效) 3.查看 cd ...

  10. 好文推荐系列--------(1)bower---管理你的客户端依赖

    好文原文地址:http://segmentfault.com/a/1190000000349555 编者注:我们发现了比较有趣的系列文章<30天学习30种新技术>,准备翻译,一天一篇更新, ...