Hdu--5139--bc

Source: Internet
Author: User

Many people use the method of offline processing.

The game didn't come up with the idea.

has been hovering between the MLE tle. Porker This is a good way to handle arrays.

I was supposed to be 1-1e7. The array range that is stored is the value of each f[n]

Now I use an array of 1-1e6 to represent F[n], G[n] g[n] is the factorial of n

Because f[n] = f[n-1] * G[n]

So when my array range is open to 1e6, it means that 0 is the solution of the N=1 1 is the solution of the n=10, and 10 of the n=100 is the solution of the n=110.

Then you can see that the number n that I want to query will fall within a certain number of [n/10,n/10+1] within this interval, which means that 15 will be between [

45 will be within [4,5].

This method is not only suitable for some of the memory requirements of high and your method enough to meet this time can be solved

At the same time, your array is best to be int to calculate, although we do not have a MLE after the above steps, but for insurance to open int to save

But in the middle of the calculation, it explodes int, so we need to convert it first to LL. After the final calculation is completed, cast to int

OK paste the code offline tomorrow and then play the game again.

1#include <iostream>2 using namespacestd;3 4 typedef __int64 LL;5 Const intSize =10000010;6 Const intMoD =1000000007;7 LL N;8 intf[1000010];9 intg[1000010];Ten  One voidInit () A { -f[0] = g[0] =1; -     intNow , next; thenow =1; -     intsum, ans; -sum =1; -      for(inti =2; i<=size-9; i++ ) +     { -Next = (int) ((1LL * (now%mod) * i)%MoD); +Ans = (int) ((1LL * (sum%mod) * (next%mod))%MoD); Anow =Next; atsum =ans; -         if(i%Ten==0 ) -            { -f[i/Ten] =ans; -g[i/Ten] =Next;  -         } in     } - } to  + intMain () - { the init (); * LL temp, sum, ans, now, next; $      while(~SCANF ("%d",&N))Panax Notoginseng     { -         if(n%Ten==0 ) the         { +printf"%d\n", f[n/Ten] ); A         } the         Else +         { -temp = n/Ten; $Ans = 1LL * f[n/Ten]; $sum =ans; -now = 1LL * g[n/Ten]; -              for(LL i = temp*Ten+1; I<=n; i++ ) the             { -Next = (int) ((now%mod) * I%MoD);WuyiAns = (int) ((sum%mod) * (next%mod)%MoD); thenow =Next; -sum =ans; Wu             } -printf"%i64d\n", ans); About         } $     } -     return 0; -}
View Code

Hdu--5139--bc

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.