Friday, 1 May 2015

UVA 568 Just the Facts (POJ 1604, ZOJ 1222, UVALive 5499, Regionals 1997 >> North America - South Central USA)

///     Raihan Ruhin
///     CSE, Jahangirnagar University.
///     Dhaka-Bangladesh.
///     id: raihanruhin (topcoder / codeforces / codechef / hackerrank / uva / uvalive / spoj), 3235 (lightoj)
///     mail: raihanruhin@ (yahoo / gmail / facebook)
///     blog: ruhinraihan.blogspot.com

#include<bits/stdc++.h>
using namespace std;

#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)

#define MOD 1000000007
#define MX 10010


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, tc, kk=1;
    string s;
    while(cin>>n)
    {
        int digit=1, tmp, five=0, two=0;
        for(int i=2;i<=n;i++)
        {
            tmp=i;
            while(tmp%2==0)
            {
                two++;
                tmp/=2;
            }
            while(tmp%5==0)
            {
                five++;
                tmp/=5;
            }
            digit = (digit*(tmp%10))%10;
        }
        //cout<<two<<endl;
        for(int i=five;i<two;i++)
            digit=(digit*2)%10;
        cout<<setw(5)<<n<<" -> "<<digit<<"\n";
    }
return 0;
}

No comments:

Post a Comment