I have a function
f(x)=(1^1)*(2^2)*(3^3)*.....(x^x)
i have to calculate (f(x)/(f(x-r)*f(r)))modulo c
i can calculate f(x) and (f(x-r)*f(r)).
assume f(x) is a
and f(x-r)*f(r) is b.
c is some number that is very larger. ``
so i how can calculate (a/b)%c
your f(x) is just ᴨ (PI cumulative multiplication) squared
g(x0,x1)=x0*(x0+1)*(x0+2)*...*x1
f(x)=g(1,x)^2
computing h(x,r,c)=f(x)/(f(x-r)*f(r))%c
h(x,r,c)=((g(1,x)/(g(1,x-r)*g(1,r)))^2)%c
sqr
as last (no need to have in sub-results)g(1,x-r)
or g(1,r)
(x-r>r)
then:h(x,r,c)=(g(x-r+1,x)/g(1,r)^2)%c
h(x,r,c)=(g(r+1,x)/g(1,x-r)^2)%c
some math tweaks
if x
is big and r
is small
b
firsta
b
a
by b
and add the result to the final division resultsome speed boost
a,b
a>1000000
then wait until the b
is also so big or wholeb>100000
....)Hope I did not make some silly math mistake...