天天看點

poj1604 Just the Facts

題意:

計算n!最後一位不為0的數。

思路:

模拟一下:

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
    int n;
    while(cin>>n)
    {
        int tmp = 1;
        for(int i = 1; i <= n; i++)
        {
            tmp *= i;
            while(tmp%10 == 0) tmp /= 10;
            tmp%= 100000;
        }   
        tmp %= 10;
    cout<<setw(5)<<n<<" -> "<<tmp<<endl;
    }
    return 0;
}