hdu 5177 (Cattleya number of 1e18 ranges)
Test instructions
Number of nth Cattleya, modulo 3814697265625 (5^18)
Limit:
There are 20 sets of data, 1 <= n <= 1e18
Ideas:
1. Expression of Cattleya number:
Ans = 1/(n+1) * C (2*n,n)
-ans = 1/(n+1) * (2n)! /n! /n! 1----
2. Because to die 5^18, to seek the inverse of the coprime, so first the "1" in the Factor 5 all removed
3. Then see the factorial that does not contain factor 5, F (n!)
4. Set g (x,n) = (x+1) (x+2) (x+3) (x+4) (x+6): (X+n) The D in%m,x+d is not a multiple of 5.
5. Then there is f (n!) =g (0,n) *g (0,N/5) *g (0,N/25) *...*g (0,0)%M---This requires the complexity of log (n)
6. For each g (x,n) we can divide the G (x,n) into two segments as evenly as possible to calculate
Part1= (x+1) (x+2) (x+3) (x+4) (x+6) *...* (x+5*k-1)
Part2= (x+5*k+1) (X+5*k +2) (X+5*k +3) (X+5*k +4) (X+5*k +6) *...* (X+5*k +5*k-1)
The remaining items are directly violent.
And then you go on and on and on---it takes the complexity of log (n)
Each time the part1 is calculated, by substituting, O (1) can calculate the Part2
The key point here is that for every polynomial, it can be made into this form:
a1*x^0 + a2*x^1 + ... + an*x^n---2-style
As you can see, for G (X,n), X is always a multiple of 5, so for each part, it generates no more than 18 entries for the "2-style". ---need 18 complexity here.
The complexity of this problem is log (2n) *log (2n) *18+log (n) *log (n) *18.
Code too frustrated, ran 7300+ms, line over, hoping to have a better way of writing the Daniel private messages to me.
HDU 5177 (Cattleya number of 1e18 ranges)