HDU-2674 N! Again (Little Tricks)

Source: Internet
Author: User

This problem has a small trick, that is, since it is n!, then to 2009 to balance, as long as more than 2009!, then must be 0, in a careful thought will find, at all, not to 2009, as long as the maximum of 2009 factorization on the line, why? Because the maximum factorization is the largest one can not be divisible by 2009, 2009 of the maximum factorization is 41, that is, as long as the factorial of more than 41 divisible by 2009, because the factorial of 41 can be divisible, 42! = 42 * 41!, so more than 41 is all 0, then the problem is simple

The code is as follows:

1#include <iostream>2#include <cstdio>3 using namespacestd;4 5 intdp[ $];6 intMain ()7 {8 9dp[0] =1;Tendp[1] =1; Onedp[2] =2; A      for(inti =3; I < $; i++) -     { -Dp[i] = dp[i-1] * I% the; the     }  -     intN; -      while(~SCANF ("%d", &N)) -     { +         if(N >= A) -Puts"0"); +         Else Aprintf"%d\n", Dp[n]); at     } -     return 0; -}

HDU-2674 N! Again (Little Tricks)

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.