SDIBT 2345 (3.2.1 factorials factorial)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.