注意会超long long

开i次根号方法,te=(ll)pow(n,1.0/i);

Yukari's Birthday

Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3262    Accepted Submission(s): 695

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
 
Source
 #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<iostream>
#define maxi(a,b) (a)>(b)?(a):(b)
#define mini(a,b) (a)<(b)?(a):(b)
#define N 1000005
#define mod 10000
#define ll long long using namespace std; ll n;
ll ans;
ll r,k;
ll rr,kk; void ini()
{
ans=n-;
r=;
k=n-;
} void cal3(ll x)
{
ll te,d;
te=+*x;
d=sqrt(te);
if(d*d==te){
kk=(d-);
if(kk%==){
kk/=;
if(kk*<ans){
ans=kk*;
k=kk;r=;
}
}
}
} ll cal(ll a,ll cnt)
{
ll re=;
while(cnt)
{
if(cnt&){
re=(re*a);
cnt--;
}
cnt/=;
a=a*a;
}
return re;
} int cal2(ll a,ll en,ll now)
{
ll i;
for(i=en;i>=;i--){
now+=cal(a,i);
if(now>n) return ;
}
if(now<n-) return ;
if(now==n- || now==n){
if(a*(en+)<ans){
ans=a*(en+);
r=en+;
k=a;
}
else{
if(a*(en+)==ans && (en+)<r){
r=en+;
k=a;
}
}
}
return ;
} void solve()
{
ll te,temp;
cal3(n);
cal3(n-);
ll i;
for(i=;i<=;i++){
//temp=cal(2ll,i);
//if(temp>n) break;
te=(ll)pow(n,1.0/i);
for(kk=te;kk>=;kk--){
temp=cal(kk,i);
if(temp>n) continue;
if(cal2(kk,i-,temp)==){
break;
}
}
}
} void out()
{
printf("%I64d %I64d\n",r,k);
} int main()
{
//freopen("data.in","r",stdin);
//scanf("%d",&T);
// while(T--)
while(scanf("%I64d",&n)!=EOF)
{
ini();
solve();
out();
}
return ;
}

hdu 4430 Yukari's Birthday 枚举+二分的更多相关文章

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

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

  2. HDU 4430 Yukari's Birthday(二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4430 题目大意:给定n个蜡烛,围绕蛋糕的中心插同心圆,从里往外分别是第1圈.第2圈....第r圈,第 ...

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

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

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

    题意:给定一个n(18 ≤ n ≤ 10^12),一个等比数列k + k^2 + .......+ k^r = n 或者 = n-1,求出最小的k*r,如果最小的不唯一,则取r更小的 分析:两个未知数 ...

  5. hdu 4430 Yukari's Birthday (简单数学 + 二分)

    Problem - 4430 题意是,给出蜡烛的数量,要求求出r和k,r是蜡烛的层数,k是每一层蜡烛数目的底数. 开始的时候,没有看清题目,其实中间的那根蜡烛是可放可不放的.假设放置中间的那根蜡烛,就 ...

  6. HDU 4430 Yukari's Birthday (二分)

    题意:有 n 个蜡烛,让你插到蛋糕上,每一层要插 k^i个根,第0层可插可不插,插的层数是r,让 r * k 尽量小,再让 r 尽量小,求r 和 k. 析:首先先列出方程来,一个是不插的一个是插的,比 ...

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

  8. hdu 4430 Yukari's Birthday

    思路: 分析知道1<=r<40:所以可以枚举r,之后再二分k. 代码如下: #include<iostream> #include<stdio.h> #includ ...

  9. zoj 3665 Yukari's Birthday(枚举+二分)

    Yukari's Birthday Time Limit: 2 Seconds       Memory Limit: 32768 KB Today is Yukari's n-th birthday ...

随机推荐

  1. ucosii(2.89)mbox 应用要点

    OSMboxCreate(void *msg)     当创建一个mbox时候,消息邮箱允许(任务或者中断)向其他一个或者几个任务发送消息.初始化msg指向消息邮箱中的消息. void*OSMboxP ...

  2. 验证IP端与数据库Ip端是否重复!!!

    select COUNT(id) from house_info_config hic where (hic.ip_start <![CDATA[<=]]> #{ipend} AND ...

  3. insert size|single-read|Paired-end|Mate-pair

    (测序方面):测三只大熊猫:得到的insert size有150bp,500bp,2kb,5kb和10kb这四种,可测得序列长度和平均reads长度. 为什么average reads这么短? 因为i ...

  4. shelll脚本,常见的脚本题目。

    [root@localhost wyb]# cat 2quan.sh #!/bin/bash #写一个脚本,先要求输入用户名,然后让他输入一个数字,输的如果是数字给输出yes,不是数字,输出no #然 ...

  5. 自写小函数处理 javascript 0.3*0.2 浮点类型相乘问题

    const reg = /^([-+]?)([0-9]+)\.([0-9]*)$/; // 判断是不是浮点数 const isFloat = function(number){ return reg. ...

  6. 使用Fiddler抓取IOS_APP的请求

    首先在地址https://www.telerik.com/fiddler 下载我们需要的fiddler 在新窗口中写上一些信息然后点击[Download for Windows]进行下载: 安装成功后 ...

  7. fsm三种建模思路比较

    ==================================================================================================== ...

  8. Python9-字典-day5

    数据类型划分:可变数据类型,不可变数据类型不可变数据类型:元祖 bool int str 可哈希可变数据类型:list,dic set 不可哈希dict key 必须是不可变数据类型,可哈希 valu ...

  9. strcpy与strcat函数原型

    1.strcpy函数原型 char *my_strcpy(char *dest,const char *src)    //const使在函数中不能修改*src其原先的值{ char *strDest ...

  10. List<T> List<?> 区别用法

    List<T>是泛型方法,List<?>是限制通配符 List<T>一般有两种用途:1.定义一个通用的泛型方法.伪代码: public interface Dao{ ...