Rokua P2726 factorial factorials label:water

Source: Internet
Author: User
Tags cmath

Topic background

The factorial writing n! of N, which represents the product of all positive integers less than or equal to N.

Title Description

The factorial will grow quickly, such as the 13! must be stored with a 32-bit integer type, to 70! That is, the use of floating-point numbers will not survive. Your task is to find the first non-0-bit factorial. As an example:

5!=1*2*3*4*5=120, so 5! The top non-0 bit is 1.

7!=1*2*3*4*5*6*7=5040, so the top non-0 bit is 5.

Input/output format

Input format:

A total of one row, a positive integer not greater than 4,220 n

Output format:

A total of one row, the output n! the last non-0 bits.

Input and Output Sample input example # #:
7
Sample # # of output:
5
Description

The title translation comes from Nocow.

Usaco Training Section 3.2

Code
1#include <iostream>2#include <algorithm>3#include <cstring>4#include <cstdio>5#include <cstdlib>6#include <cmath>7 #defineM 2621448 using namespacestd;9 Ten intN; One  A intMain () { - //freopen ("01.in", "R", stdin); -scanf"%d",&N); the      -     Long Longans=1; -      for(Long LongI=1; i<=n;i++){ -ans*=i; +          while(ans%Ten==0) ans/=Ten; -ans%=100000000; +     } Acout<< (ans%Ten) <<Endl; atFclose (stdin); fclose (stdout);return 0; -}

Error, the sample is also wrong, the above code can be AC, that is, the output of the last one, sample 7→5

But this subject does not change the words can be so, no data do not know

1#include <iostream>2#include <algorithm>3#include <cstring>4#include <cstdio>5#include <cstdlib>6#include <cmath>7 #defineM 2621448 using namespacestd;9 Ten intN; One  A intMain () { -Freopen ("01.in","R", stdin); -      while(SCANF ("%d", &n) = =1){ the         Long Longans=1; -          for(Long LongI=1; i<=n;i++){ -ans*=i; -          while(ans>=1000000000) ans/=Ten; +     //cout<<ans<<endl; -         } +          while(ans>Ten) ans/=Ten; Acout<<ans<<Endl; at     } -      -  -Fclose (stdin); fclose (stdout);return 0; -}

To the back of the accuracy may have a gap to be determined

Rokua P2726 factorial factorials label:water

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.