Yukari's Birthday


Time Limit: 2 Seconds       Memory Limit: 32768 KB

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
这题是周赛的时候做的,不过我赛后自己写还写了几个小时,能力不行啊,老是出错
这题算幂的时候最好调用系统的pow函数,算法一样调用pow的能比我的快几倍。这也是事后才发现的,因为不管我怎么优化就是比别人的慢许多
至于这个题目中所说的如果有相等的r*k取r最小的,我写出了r*k的表达式,对它求导之后发现它是关于k单调递增的,我直接从r最大时开始,这样第一个找到的k就是最小的一旦找到立马退出,可以A。至于到底有没有那种几个r*k相等的情况我也不能证明出来
#include<stdio.h>
#include<math.h>
double logn;
long long n;
long long fun(long long k,int i)
{
int j;
long long s=1,sum=0;
for(j=0;j<i;j++)
{
if(s>n/k)
return n+1;
s*=k;
sum+=s;
if(sum>n)
return n+1;
}
return sum;
}
int main()
{
int i,j,r,num;
long long minx,mink,minr,min,max,mid,ki,temp;
while(scanf("%lld",&n)!=EOF)
{
logn=log((double)n);
num=log((double)n)/log(2.0);
minx=n;
for(i=num;i>=1;i--)//枚举r
{
min=1;
max=n;
while(min<=max)
{
mid=(min+max)/2;
temp=fun(mid,i);
if(temp>n)
max=mid-1;
else if(temp<(n-1))
min=mid+1;
if(temp==n||temp==n-1)
{
if(minx>i*mid)
{
minx=i*mid;
mink=mid;
minr=i;
}
break;
}
}
}
printf("%lld %lld\n",minr,mink);
}
return 0;
}


zoj 3665 Yukari's Birthday(枚举+二分)的更多相关文章

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

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

  2. HDU 4430 &amp; ZOJ 3665 Yukari&#39;s Birthday(二分法+枚举)

    主题链接: HDU:pid=4430" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=4430 ...

  3. hdu 4430 Yukari's Birthday 枚举+二分

    注意会超long long 开i次根号方法,te=(ll)pow(n,1.0/i); Yukari's Birthday Time Limit: 12000/6000 MS (Java/Others) ...

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

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

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

  6. HDU - 4430 Yukari's Birthday(二分+枚举)

    题意:已知有n个蜡烛,过生日在蛋糕上摆蜡烛,将蜡烛围成同心圆,每圈个数为ki,蛋糕中心最多可摆一个蜡烛,求圈数r和看,条件为r*k尽可能小的情况下,r尽可能小. 分析:n最大为1012,k最少为2,假 ...

  7. hdu4430之枚举+二分

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

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

随机推荐

  1. 有关于/home出现100%被占用 与 vnc的关系

    我在远程服务器时,通常使用的程序是vnc.因为vnc可以图形化界面,操作效果比用putty好很多. 但是,我发现使用vnc有一个问题,就是/home占用空间会达到100%. [zy@islab62 ~ ...

  2. Delphi实现全局鼠标钩子

    其中涉及到的一些API,网上均能查到详细的解释,这里不再熬述.源码下载 因为是全局钩子,所以要用dll注入.用到的鼠标消息结构如下: PMouseHookStruct = ^TMouseHookStr ...

  3. memcache 安装教程

    memcached:官网http://memcached.org/ 说明:memcached本身没有Linux版本,网上的windows 版本都是个人开发的. memcached和memcache区别 ...

  4. css案例学习之层叠样式

    代码 <html> <head> <title>层叠特性</title> <style type="text/css"> ...

  5. 借助bootstrap框架模仿airbnb写的网页

    View HTML .nav a { color: #5a5a5a; font-size: 11px; font-weight: bold; padding: 14px 10px; text-tran ...

  6. Mysql中Key与Index的区别

    mysql的key和index多少有点令人迷惑,这实际上考察对数据库体系结构的了解的. 1 key 是数据库的物理结构,它包含两层意义,一是约束(偏重于约束和规范数据库的结构完整性),二是索引(辅助查 ...

  7. VS2015 开发人员命令提示,如何实现记事本编程

    开始,选择VS2015 开发人员命令提示,打开 找到.c文件的位置,复制位置 在VS2015 开发人员命令提示, 输入cd 位置 回车 然后输入cl 文件名 回车 这样进行编译

  8. uva 10004 Bicoloring(dfs二分染色,和hdu 4751代码差不多)

    Description In the ``Four Color Map Theorem" was proven with the assistance of a computer. This ...

  9. Mongo散记--聚合(aggregation)&amp; 查询(Query)

    mongo官网:http://www.mongodb.org/ 工作中使用到Mongo,可是没有系统的学习研究过Mongo,仅对工作过程中,在Mongo的使用过程中的一些知识点做一下记录,并随时补充, ...

  10. Cocos2dx 中的CCCallFunc,CCCallFuncN,CCCallFuncND,CCCallFuncO比较

    qinning199原创,欢迎转载.转载请注明:http://www.cocos2dx.net/?p=27 首先看一张图片,表示了CCCallFunc的继承关系: 1.CCCallFunc,回调,调用 ...