注意会超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. htmlunit抓取js执行后的网页源码

    上次我不是写了一个自动抓取博客访问量吗 (点击打开链接) 可是昨天晚上我又运行的时候,发现不能用了.. 运行了几次 发现使用URLConnection 得到的网页源码和浏览器直接查看的不同. URLC ...

  2. 由DAG到背包问题——记忆化搜索和递推两种解法

    一.问题描述 物品无限的背包问题:有n种物品,每种均有无穷多个.第 i 种物品的体积为Vi,重量为Wi.选一些物品装到一个容量为 C 的背包中,求使得背包内物品总体积不超过C的前提下重量的最大值.1≤ ...

  3. tkinter学习-文本框

    阅读目录 Entry 输入框 Text 文本框 Entry: 说明:输入控件,用于显示简单的文本内容 属性:在输入框中用代码添加和删除内容,同样也是用insert()和delete()方法 from ...

  4. docker系列之基础命令-1

    1.docker基础命令 docker images 显示镜像列表 docker ps 显示容器列表 docker run IMAGE_ID 指定镜像, 运行一个容器 docker start/sto ...

  5. 纯 CSS 创作一个小球绕着圆环盘旋的动画

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/gKxyWo 可交互视频 ...

  6. [Redis]ResponseError: Client sent AUTH, but no password is set

    由于在代码中给redis添加了密码,如下 redis_store = redis.Redis(host='localhost', port=6379, db=4, password='root') 然 ...

  7. selenium.common.exceptions.WebDriverException: Message: u'unknown error: cannot get automation extension\nfrom unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfeb

    Python2.7 selenium3.4.1在使用chrome driver时报错:selenium.common.exceptions.WebDriverException: Message: u ...

  8. 牛客网暑期ACM多校训练营(第六场) J Heritage of skywalkert(数论, eth_element)

    链接: https://www.nowcoder.com/acm/contest/144/J 题意: 给定一个函数, 求它n次结果中任意两次的lcm最大值 分析: 首先要看出这个函数并没有什么含义, ...

  9. tomcat启动后 404 页面无法访问

    如果修改端口后还不能访问,先关闭tomcat, 在bin目录下命令 ./shutdown.sh 找到80进程  netstat -an | grep 80 杀死80进程 ps -ef | grep h ...

  10. iOS 开发之多线程之GCD

    1.GCD(Grand Centrol Dispath) 并行:宏观以及微观都是两个人再拿着两把铁锹在挖坑,一小时挖两个大坑 并发:宏观上是感觉他们都在挖坑,微观是他们是在使用一把铁锹挖坑,一小时后他 ...