Descrtion:
Please help Xiao Ming Write a Super Fast Function which result was 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 an 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 a line one case.
Sample Input:
1 1 1
3 2 3
5 11 2
Sample output:
0
-1
-1
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <string>5#include <algorithm>6 7 using namespacestd;8 9 intMain ()Ten { One #ifdef OFFLINE AFreopen ("In.txt","R", stdin); -Freopen ("OUT.txt","W", stdout); - #endif the - intA, B, C; - while(SCANF ("%d%d%d", &a, &b, &c)! =EOF) - { + DoubleFF =1, FL =0, pf =1, PL =0; - + for(inti =1; I <= A; i++) A { atFF = FF *i; - while(FF >=100000000) FF/=Ten; -FL + = log10 ((Double) (i); - } - - for(inti =0; I < C; i++) in { -PF = PF *b; to while(PF >=100000000) PF/=Ten; +PL + = log10 ((Double) b); - } the *FL = Floor (FL) +1; $PL = Floor (PL) +1;Panax Notoginseng - if(fl < PL | | (fl = = PL && FF <PF)) theprintf"-1\n"); + Else if(fl > PL | | (fl = = PL && ff >PF)) Aprintf"1\n"); the Else +printf"0\n"); - } $ $ return 0; -}
View Code
Large number size comparison: Easy Function