Friday 16 December 2016

modular arithmetic - modulo of series summation

I have trouble with computing modulo.
First, I have a summation of series like this:
$$1+3^2+3^4+\cdots+3^n$$
And this is the formula which can be used to compute the series:
$$S=\frac{1-3^{n+2}}{1-3^2}=\frac{3^{n+2}-1}{8}$$
Then I want to compute $S \mod 1000000007$. But if $n$ is a large number, it's really hard for me to compute it. The only thing I know is $3^{n+2}-1$ divisible by 8 (n is an even number). Could anyone give me some good hint to solve this problem?




Update
My intention is computing $$M=\frac{3^{n+2}-1}{8} \mod 1000000007$$
For example: If $n=4000$ I must split $3^{4000+2}$ into $3^{40}3^{40}...3^{40}3^2$ and compute modulo for each part to improve speed like this:
$$(3^{40}\mod 1000000007)(3^{40}\mod 1000000007)...(3^{40}\mod 1000000007)3^2$$
But how can I compute M with the above idea.



Update more
It seems related to inverse modulo. I think the problem was solved like this
$$I=\frac{(1000000007+1)}{8}=125000001$$
$$\frac{3^{n+2}-1}{8} \mod 1000000007=(3^{n+2}I-I)\mod 1000000007$$
Is it right?

No comments:

Post a Comment

real analysis - How to find $lim_{hrightarrow 0}frac{sin(ha)}{h}$

How to find $\lim_{h\rightarrow 0}\frac{\sin(ha)}{h}$ without lhopital rule? I know when I use lhopital I easy get $$ \lim_{h\rightarrow 0}...