Yukari's Birthday

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 2549    Accepted Submission(s): 522

Problem Description
Today is Yukari's n-th birthday. Ran and Chen hold a celebration party for her. Now comes the most important part, birthday cake! But it's a big challenge for them to place n candles on the top of the cake. As Yukari has lived for such a long long time, though
she herself insists that she is a 17-year-old girl.

To make the birthday cake look more beautiful, Ran and Chen decide to place them like r ≥ 1 concentric circles. They place ki candles equidistantly on the i-th circle, where k ≥ 2, 1 ≤ i ≤ r. And it's optional to place at most one candle at the center
of the cake. In case that there are a lot of different pairs of r and k satisfying these restrictions, they want to minimize r × k. If there is still a tie, minimize r.
 
Input
There are about 10,000 test cases. Process to the end of file.

Each test consists of only an integer 18 ≤ n ≤ 1012.
 
Output
For each test case, output r and k.
 
Sample Input
18
111
1111
 
Sample Output
1 17
2 10
3 10
 

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#define INF 99999999
typedef __int64 LL;
using namespace std; const int MAX=1000+10;
LL n; LL cal(LL k,LL r){
LL sum=1,ans=0;
for(int i=1;i<=r;++i){
if(n/sum<k)return n+1;
sum=sum*k;//sum*k可能会溢出
ans+=sum;
if(ans>n)return ans;//ans大于n直接返回
}
return ans;
} LL search(LL i){
LL l=2,r=n;
while(l<=r){
LL mid=(l+r)>>1;
LL sum=cal(mid,i);
if(sum == n-1 || sum == n)return mid;
if(sum<n-1)l=mid+1;
else r=mid-1;
}
return -1;
} int main(){
while(~scanf("%I64d",&n)){
LL a=1,b=n-1;
for(LL i=2;i<=60;++i){//枚举r然后对k进行二分查找,由于k>?=2,2^60>10^12,所以i仅仅要枚举到60就可以
LL k=search(i);
if(k != -1 && i*k<a*b){a=i,b=k;}
}
printf("%I64d %I64d\n",a,b);
}
return 0;
}

hdu4430之枚举+二分的更多相关文章

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

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

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

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

  3. 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 ...

  4. hdu4430 枚举+二分

    Yukari's Birthday Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  5. 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 ...

  6. HDU 4282 A very hard mathematic problem --枚举+二分(或不加)

    题意:问方程X^Z + Y^Z + XYZ = K (X<Y,Z>1)有多少个正整数解 (K<2^31) 解法:看K不大,而且不难看出 Z<=30, X<=sqrt(K) ...

  7. Subset---poj3977(折半枚举+二分查找)

    题目链接:http://poj.org/problem?id=3977 给你n个数,找到一个子集,使得这个子集的和的绝对值是最小的,如果有多种情况,输出子集个数最少的: n<=35,|a[i]| ...

  8. hdu 5288 OO’s Sequence 枚举+二分

    Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...

  9. codeforces 613B B. Skills(枚举+二分+贪心)

    题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'empid' in 'class cn.happy.entity.Emp'

    org.apache.ibatis.exceptions.PersistenceException: ### Error querying database.  Cause: org.apache.i ...

  2. 【转】Java 集合系列06之 Vector详细介绍(源码解析)和使用示例

    概要 学完ArrayList和LinkedList之后,我们接着学习Vector.学习方式还是和之前一样,先对Vector有个整体认识,然后再学习它的源码:最后再通过实例来学会使用它.第1部分 Vec ...

  3. node.js安装步骤

    首先这是node.js的官网:https://nodejs.org/en/ 截至2017年12月9日,node更新在8.9.3该版本,建议开发人员下载6.0以上版本,8以上不是很稳定!  如果有其他需 ...

  4. unity3d 各键值对应代码

    KeyCode :KeyCode是由Event.keyCode返回的.这些直接映射到键盘上的物理键.  值        对应键 Backspace     退格键 Delete      Delet ...

  5. 重绘DataGridView的DataGridViewCheckBoxCell控件

    最近项目中要用到在DataGridView单元格里面放置一个带有文本的 DataGridViewCheckBoxCell控件但原有 的是不支持的然后我就想着重写个 DataGridViewCheckB ...

  6. 用nginx实现分布式限流

    1.前言 一般对外暴露的系统,在促销或者黑客攻击时会涌来大量的请求,为了保护系统不被瞬间到来的高并发流量给打垮, 就需要限流 . 本文主要阐述如何用nginx 来实现限流. 听说 Hystrix 也可 ...

  7. Nagios事件机制实践

    Nagios事件机制实践  blog地址:http://www.cnblogs.com/caoguo 一.事件触发执行脚本 [root@Nagios ~]# cd /usr/local/nagios/ ...

  8. layer:好看的弹出窗口

    layer是一款web弹层组件,只需在调用时简单地配置相关参数,即可轻松实现丰富与便捷的操作体验. 这是layer的官方地址,里面的使用介绍非常详细(http://layer.layui.com/) ...

  9. (转)淘淘商城系列——初始SolrCloud

    http://blog.csdn.net/yerenyuan_pku/article/details/72944611 本文我只是简单介绍一下SolrCloud,如果大家要是感兴趣的话,可以参考Sol ...

  10. tp定时任务,传参问题

    <?phpnamespace app\command; use think\console\Command;use think\console\Input;use think\console\i ...