Description
The factorial writing of n n! represents the product of all positive integers less than or equal to N. The factorial will quickly become larger, as 13! must be stored with a 32-bit integer type, 70! Even with floating-point numbers. Your task is to find the last non-0-bit of factorial. For example, 5!=1*2*3*4*5=120 so 5! The last side of the non-0-bit is 2,7! =1*2*3*4*5*6*7=5040, so the last non-0 bits of the surface are 4.
Input
A total of one row, an integer not greater than 4,220 of N.
Output
A total of one row, output n! the last non-0 bits.
Sample Input
7
Sample Output
4
1#include <stdio.h>2 3 intMain ()4 {5 intn,date[ the],cnt=0;6 inti,sum=1;7scanf"%d",&n);8 for(I=n; i>=1; i--)9 {Tendate[i]=i; One while(date[i]%5==0)//Culling 5 A { -Date[i]/=5; -cnt++; the } - } - for(I=n; i>=1; i--)//eliminate the same number of 2 so that No 10 will be present. - { + if(cnt==0) - Break; + while(date[i]%2==0&&cnt!=0) A { atDate[i]/=2; -cnt--; - } - } - for(I=n; i>=1; i--) -Sum= (Sum*date[i])%Ten; inprintf"%d\n", sum); - return 0; to}
View Code
SDIBT 2345 (3.2.1 factorials factorial)