UVA 568 Just The Facts (factorial)

Source: Internet
Author: User

Test instructions: To find the factorial of a number n, the number of the 1th is not the number of 0.

Train of thought: [1,n] Multiply each, appear suffix 0 to filter out, for example 12300 becomes 123, continue to count down. To solve the problem of long long, the remaining number of mods, filter out the previous too large part, because the calculation is useless. How much should this mod be? 1 billion on the line.

1#include <bits/stdc++.h>2 #defineLL Long Long3 using namespacestd;4 Const intn=10001;5 Const intMod=1000000000;6 intAns[n];7 8 voidInit ()9 {TenLL fun=1; Oneans[1]=1; A      for(intI=2; i<n; i++) -     { -fun*=i; the          while(fun%Ten==0) -Fun/=Ten;//filter out the suffix 0 -ans[i]=fun%Ten;//take the last one . -fun%=MoD; +     } - } +  A intMain () at { -     //freopen ("Input.txt", "R", stdin); - init (); -     intA; -      while(~SCANF ("%d",&a)) -printf"%5d-%d\n", A,ans[a]); in     return 0; -}
AC Code

UVA 568 Just The Facts (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.