注意会超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. Python-OpenCV:cv2.imread(),cv2.imshow(),cv2.imwrite()

    为什么使用Python-OpenCV? 虽然python 很强大,而且也有自己的图像处理库PIL,但是相对于OpenCV 来讲,它还是弱小很多.跟很多开源软件一样OpenCV 也提供了完善的pytho ...

  2. Java的jdbc调用SQL Server存储过程Bug201906131120

    如果要查询结果,第一行使用set nocount on;可能可以解决问题.

  3. shell脚本,按单词出现频率降序排序。

    [root@localhost oldboy]# cat file the squid project provides a number of resources toassist users de ...

  4. Xcode中的约束用法

    这篇文章用几个简单的例子来介绍XCode6.1故事板中约束的使用方法.   现在iOS设备屏幕的尺寸也有很多种了,尤其是有了iPhone6 Plus以后,再不关注界面的尺寸适配就有点说不过去了.   ...

  5. MySQL binlog-server搭建

    MySQL binlog-server搭建 binlog在备份中起着至关重要的作用,备份binlog文件时,只能先在本地备份,然后才能传送到远程服务器上.从MySQL5.6版本后,可以利用mysqlb ...

  6. Spring中使用注解 @Scheduled 执行定时任务

    来自:http://blog.51cto.com/dwf07223/1557145 注解@Scheduled 可以作为一个触发源添加到一个方法中,例如,以下的方法将以一个固定延迟时间5秒钟调用一次执行 ...

  7. Web安全XSS、CSRF和SQL注入

    SQL注入 SQL注入是以用户的输入作为sql语句的一部分,如后端接收到用户的请求数据后,不经过数据转义,就把数据拼接到SQL中执行,容易导致SQL的语义被篡改,即受到攻击了. 解决办法是对接收的数据 ...

  8. Web框架之Django_09 重要组件(Django中间件、csrf跨站请求伪造)

    摘要 Django中间件 csrf跨站请求伪造 一.Django中间件: 什么是中间件? 官方的说法:中间件是一个用来处理Django的请求和响应的框架级别的钩子.它是一个轻量.低级别的插件系统,用于 ...

  9. LeetCode(79) Word Search

    题目 Given a 2D board and a word, find if the word exists in the grid. The word can be constructed fro ...

  10. Aizu-ALDS1_3_A:Stack

    D - Stack Write a program which reads an expression in the Reverse Polish notation and prints the co ...