Factorial problem time limit: 1 Sec memory limit: MB
Submitted: $ 13 Resolution:
Submitted State [Discussion Version] Title Description Perhaps you already know the meaning of factorial, n factorial is multiplied by 1 to N, such as:
12! = 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x Ten x x 12 = 479,001,600
The rightmost non-0 bit of the factorial of 12 is 6.
Write a program that calculates the rightmost non-0-bit value of the N (1<=n<=50,000,000) factorial.
NOTE: 10,000,000! There are 2,499,999 zeros.
Enter only one row containing a positive integer n. Output
A single line contains an integer representing the rightmost non-0-bit value.
Sample input
12
Sample output
6
#include <cstdio>#include<algorithm>#definell Long Long#defineMAXN 800010#defineLson l,m,rt<<1#defineRson m+1,r,rt<< 1 | 1using namespacestd;ints[ -];intMain () {intnum,n,add,pai[4]={6,2,4,8}; while(~SCANF ("%d",&N)) {num=N; Add=0; while(num) {if(num%5==2) {Add+=1; } Else{ if(num%5==4) Add+=2; } Add+=num/5; Num/=5; } if(n>1) {printf ("%d\n", pai[add%4]); } Elseprintf"1\n"); }}
Factorial problem n! After the rightmost number is not 0