传送: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. Java基本语法实验报告

      题目:       Java基本语法 课程名称:  JAVA语言程序设计 班    级:    信1705-1 姓    名:   刘雨馨     学号:   20173445 指导教师:    ...

  2. Mybatis简介、环境搭建和详解

    简介: 1.Mybatis  开源免费框架,原名叫iBatis,2010在google code,2013年迁移到github 2.作用: 数据访问层框架 2.1  底层是对JDBC的封装 3.myb ...

  3. java 模拟登录新浪微博(通过cookie)

    这几天一直在研究新浪微博的爬虫,发现爬取微博的数据首先要登录.本来打算是通过账号和密码模拟浏览器登录.但是现在微博的登录机制比较复杂.通过账号密码还没有登录成功QAQ.所以就先记录下,通过cookie ...

  4. Docker学习以及镜像制作流程

    一.何为Docker Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从Apache2.0协议开源. Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后 ...

  5. 关于SQL表字段值缺失的处理办法

    在计算收益率时候,  收益率 = 收益 / 成本 一.如果成本为0,NULL,此时无法计算收益率: 方法: 1.将成本为0的数据 运算 (case when  cost =0 or cost is n ...

  6. 修正剑桥模型预测-用python3.4

    下面是预测结果: #!/usr/bin/env python # -*- coding:utf-8 -*- # __author__ = "blzhu" ""& ...

  7. 写了十年JS却不知道模块化为何物?

    作者:肖光宇 野狗科技联合创始人,先后在猫扑.百度.搜狗任职,爱折腾的前端工程师. 野狗官博:https://blog.wilddog.com/ 野狗官网:https://www.wilddog.co ...

  8. AngularJS中$interval和$timeout的使用

    我们在项目中会出现定时刷新,延迟加载等多种场景. 接下来就看$interval和$timeout的使用 $interval可用于定时任务,我们只需在controller注入$interval即可使用. ...

  9. x86_64汇编调试程序初步

    寄存器说明: rdi 存第1个参数(值或地址) rsi 存第2个参数 rdx 存第3个参数 rcx 存第4个参数 r8 存第5个参数 r9 存第6个参数 rax 第1个返回值 rdx 第2个返回值 r ...

  10. 开源HIS之C/S选型

    客户端/服务的形式是我中爱的,我认可只有这样软件跑起来不会失控.因为你不知道每一个程序员是否足够清醒.但一开始我说过要从基本的应急的门诊收费开始,所以我并不打算一启动就写一个服务,并为之选型:TCP/ ...