USACO 3.2.1 Factorials

USACO 3.2.1 Factorials

每次相乘的结果去掉尾部的0 之后,  mod 10000, 仅保留五位.

/**/ /*
ID: lorelei3
TASK: fact4
LANG: C++
*/


#include 
< fstream >

using   namespace  std;

int  n;

int  main() {

    unsigned 
long res = 1;
    ifstream fin(
"fact4.in");
    ofstream fout(
"fact4.out");

    fin
>>n;


    
for(int i=2; i<=n; ++i){
        res 
*= i;
        
while(res%10==0)
            res 
/=10;
        res 
%= 100000 ;
    }


    fout
<< res%10 <<endl;
        
    
return 0;
}

你可能感兴趣的:(USACO 3.2.1 Factorials)