标签:
Descrtion:
Please help Xiao Ming Write a Super Fast Function which result is like below:int cmp(int a, int b, int c)
{
SuperLong factorial = 1;
for (int i = 1; i <= a; i++)
factorial *= i;SuperLong power = 1;
for (int i = 1; i <= c; i++)
power *= b;if (factorial < power)
return -1;
else if (factorial == power)
return 0;
else
return 1;
}SuperLong is a type of integer with unlimited length.
Input:
Input contains multiple test case.One line one case, and each case is three integers, a, b, c.
We guarantee that 1 <= a,b,c <= 20000.Output:
For each case, print the function result, and one line one case.Sample input:
1 1 1
3 2 3
5 11 2Sample output:
0
-1
-1
1 #include <cstdio> 2 #include <iostream> 3 #include <cstring> 4 #include <string> 5 #include <algorithm> 6 7 using namespace std; 8 9 int main() 10 { 11 #ifdef OFFLINE 12 freopen("in.txt", "r", stdin); 13 freopen("out.txt", "w", stdout); 14 #endif 15 16 int a, b, c; 17 while (scanf("%d%d%d", &a, &b, &c) != EOF) 18 { 19 double ff = 1, fl = 0, pf = 1, pl = 0; 20 21 for (int i = 1; i <= a; i++) 22 { 23 ff = ff * i; 24 while (ff >= 100000000) ff /= 10; 25 fl += log10((double)i); 26 } 27 28 for (int i = 0; i < c; i++) 29 { 30 pf = pf * b; 31 while (pf >= 100000000) pf /= 10; 32 pl += log10((double)b); 33 } 34 35 fl = floor(fl) + 1; 36 pl = floor(pl) + 1; 37 38 if (fl < pl || (fl == pl && ff < pf)) 39 printf("-1\n"); 40 else if (fl > pl || (fl == pl && ff > pf)) 41 printf("1\n"); 42 else 43 printf("0\n"); 44 } 45 46 return 0; 47 }
标签:
原文地址:http://www.cnblogs.com/gwsbhqt/p/4457651.html