TOJ 4373 HDU 4430 ZOJ 3665 Yukari ' s Birthday/two min

Source: Internet
Author: User
Tags min time limit
Yukari ' s Birthday time limit (normal/java): 1000ms/3000ms Run memory limit: 65536KByte


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 Placen candles on the top of the cake. As Yukari have lived for such a long long time. Though she herself insists that she's a 17-year-old girl.



The birthday cake look more beautiful, Ran and Chen decide to place them liker≥1 concentric circles. They place Ki candles equidistantly on thei-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 is a lot of different pairs ofr and K satisfying these restrictions, they want to minimizerxk. If There is still a tie, minimize R.






input






There is about the test cases. Process to the end of file.



Each test consists is an integer 18≤n≤1012.






Output






For each test case, output R and K.






Sample Input





1111 111











Sample Output





1
2
3 10





Assuming k minimum is 2 then R Max 45 2 45 times more than 10 times



Then enumerate r binary K



The two-time lvalue L is obviously from 2 R words I start from 100w because 100w squared is greater than or equal to n maximum



For the left and right range of the dichotomy is not very well judged



Rotten Code


 #include <stdio.h> const long Long MAX = 1000010; long long N;
	A long long check (long long K,long long R) {Long Long res = 0,i,m = k;
		for (i = 1;i <= r; i++) {res + = m;
		printf ("%i64d\n", res);
		M *= K;
	if (res > N) return max * MAX;
} return res;
	A long long erfen (long long L,long long R,long long k) {if (k = = 1) return n-1;
		while (L <= R) {Long Long M = (L + r) >> 1;
		Long Long res = check (m,k);
		printf ("%i64d\n", res);
		
		if (res = = N | | res = = n-1) return m;
		if (res > N) r = m-1;
	else L = m + 1;
} return-1;
	} int main () {Long long l,r,i,r,k,rr,kk;
		while (scanf ("%lld", &n)!=eof) {RR = MAX;
		KK = MAX;
			for (i = 1;i <=; i++) {L = 2;
			R = 1000000;
			Long Long res = Erfen (l,r,i);
					if (res! =-1) {if (res * i < RR * KK | | res * i = = RR * KK && i < RR) {rr = i;
				KK = res;
	}}} printf ("%lld%lld\n", RR,KK);
} return 0; }
	#include <stdio.h>
const long long MAX = 1000010;
long long n;

long long check (long long k, long long r)
{
long long res = 0, i, m = k;
for (i = 1; i <= r; i ++)
{
res + = m;
// printf ("% I64d \ n", res);
m * = k;
if (res> n)
return MAX * MAX;
}
return res;
}
long long erfen (long long l, long long r, long long k)
{
if (k == 1)
return n-1;
while (l <= r)
{
long long m = (l + r) >> 1;
long long res = check (m, k);
// printf ("% I64d \ n", res);
if (res == n || res == n-1)
return m;
Hell
if (res> n)
r = m-1;
else
l = m + 1;
}
return -1;
}
int main ()
{
long long l, r, i, R, K, RR, KK;
while (scanf ("% lld", & n)! = EOF)
{
RR = MAX;
KK = MAX;
for (i = 1; i <= 40; i ++)
{
l = 2;
r = 1000000;
long long res = erfen (l, r, i);
if (res! = -1)
{
if (res * i <RR * KK || res * i == RR * KK && i <RR)
{
RR = i;
KK = res;
}
}
}
printf ("% lld% lld \ n", RR, KK);
}
return 0;
} 


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.