Large number size comparison: Easy Function

Source: Internet
Author: User

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

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.