[Login|Register]
New post

Show post

Search forum

Read post
Why my program is always WA? [ Topic ] 2012-04-27 21:31:03 hsiven
#include <stdio.h>
int GetNumFac(int num , long fac)
{
    int result = 0 ;
    while(num >= fac)
    {
        result += num / fac ;
    num /= fac ;
    }
    return result ;
}
int GetLastDigit(int num)
{
    int totalfac = GetNumFac(num , 5) ;
    int count = 0 ;
    int result = 1 ;
    int i , temp ;
    for(i = num ; i >= 2 ; -- i)
    {
        temp = i ;
        while(temp % 2 == 0 && count < totalfac)
    {
        temp /= 2 ;
        ++ count ;
    }
    while(temp % 5 == 0)
        temp /= 5 ;
    temp %= 10 ;
    result *= temp ;
    result %= 10 ;
    }
}
int main()
{
    int n ;
    while(scanf("%d" , & n) != EOF)
    {
        if(n == 0)
        printf("%5d -> 1\n" , n) ;
        else
            printf("%5d -> %d\n" , n , GetLastDigit(n)) ;
    }

    return 0 ;
}
Reply
Title
Message
(64K)
University of Science and Technology of China
Online Judge for ACM/ICPC
Processed in 1.4ms with 2 query(s).