首页 > 其他 > 详细

USACO 3.2 Factorials (fact4)

时间:2014-02-28 12:16:48      阅读:433      评论:0      收藏:0      [点我收藏+]
/*
F[i] denote the 5 digits from rightmost non-zero digit of i! ;
There is a trap, we can‘t just store the rightmost non-zero digit of i!
Eg: 15 * 2 = 30 may affect the second last digit;
Since N is 4220 at most, we should store 5 digits;
*/
/*
ID: haolink1
PROG: fact4
LANG: C++
*/

//#include <iostream>
#include <fstream>
using namespace std;
int F[4221];
int limit = 100000; 
int main(){
    ifstream fin("fact4.in");
    ofstream cout("fact4.out");
    int N = 0;
    fin >> N;
    F[1] = 1;
    int i = 1;
    while(i < N){
        i++;
        int tmp = F[i-1] * i;
        int remain = tmp % 10;
        while(!remain){
            tmp /= 10;
            remain = tmp%10;
        }
        F[i] = tmp % limit;
    } 
    cout << F[N] % 10<< endl;
    return 0;
}

USACO 3.2 Factorials (fact4),布布扣,bubuko.com

USACO 3.2 Factorials (fact4)

原文:http://blog.csdn.net/damonhao/article/details/20046755

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!