Hdoj 4430 Yukari's birthday

Source: Internet
Author: User


The high accuracy of C ++ is too painful ....

Yukari's birthday Time Limit: 12000/6000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 2891 accepted submission (s): 604


Problem descriptiontoday 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 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.
 
Inputthere are about 10,000 test cases. process to the end of file.
Each test consists of only an integer 18 ≤ n ≤ 1012.
 
Outputfor each test case, output R and K.
Sample Input
181111111
 
Sample output
1 172 103 10
 
Source2012 Asia Changchun Regional Contest



#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;typedef long long int LL;LL n;LL check(LL r){    LL low=2,high=n,mid,ret=-1;    while(low<=high)    {        mid=(low+high)/2;        if(((LL)(pow(mid*1.,r-1.))>n||(LL)(pow(mid*1.,r-1.))<0)           ||(LL)(pow(mid*1.,r*1.))>n||(LL)(pow(mid*1.,r*1.))<0)        {            high=mid-1;            continue;        }        LL temp=mid*(1-(LL)(pow(mid*1.,r*1.)))/(1-mid);        if(temp<=n-1||temp<=n)        {            if(temp==n||temp==n-1) ret=mid;            low=mid+1;        }        else        {            high=mid-1;        }    }    return ret;}int main(){while(scanf("%I64d",&n)!=EOF){    LL R=1,K=n-1,ans=(1LL<<60);    for(LL r=2;r<40;r++)    {        LL k=check(r);        if(k==-1) continue;        if(ans>r*k)        {            R=r; K=k;        }    }    printf("%I64d %I64d\n",R,K);}    return 0;}


Hdoj 4430 Yukari's birthday

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.