-1

How can I find the value of $$\frac{10^{a\cdot b}-1}{10^b-1}\mod P$$
I tried writing it as a GP : $1,10^b,10^{2b},...10^{(a-1)b}$
$\therefore$ If $P$ is a multiple of $2$ or $5$, it will always be $1$. And if it is prime I can use fermat's little theorem and inverse modulo to find it.
But How to proceed if $P$ is not prime?

Thomas Andrews
  • 177,126
maverick
  • 1,319

1 Answers1

2

(Now with a real answer.)

Deleting full answer since it is a contest problem.

Will keep this mathematical hint:

$$\begin{pmatrix}z&1\\0&1\end{pmatrix}^n = \begin{pmatrix}z^n&1+z+\cdots z^{n-1}\\0&1\end{pmatrix}$$

Thomas Andrews
  • 177,126
  • @ThomasAndrews Thanks a lot. But I found this question as a duplicate.. deleting.. – maverick Feb 03 '17 at 21:22
  • 1
    @ThomasAndrews Yes certainly. http://stackoverflow.com/a/9486650/6151597 – maverick Feb 03 '17 at 21:28
  • Yes thanks a lot for your hardwork. Its perfect! – maverick Feb 03 '17 at 21:30
  • @Thomas Seems to be Code Chef contest problem, see my comment on the question. – Bill Dubuque Feb 03 '17 at 22:06
  • Yes, so I see. Ugh. Disappointing since I enjoyed the problem so much. @BillDubuque – Thomas Andrews Feb 03 '17 at 22:12
  • @Thomas I definitely sympathize. Nice answer +1 – Bill Dubuque Feb 03 '17 at 22:15
  • I think my shorter "hint" answer is even better - more math-y, less programmy. :) – Thomas Andrews Feb 03 '17 at 22:30
  • Bill Gosper has some nice elaborate matrix product formulas that he uses to to derive Ramanujan-inspired identities. Iirc some can be found in his "strip mining in abandoned Ore fields" paper, or in various MIT AI Lab memos (some tidbits iin HAKMEM) – Bill Dubuque Feb 03 '17 at 22:58
  • 1
    Readers may also find of interest the general addition law for $,f_n = \dfrac{x^n-y^n}{x-y},,$ i.e. $, f_{m+n} = f_{m+1} f_n - xy, f_m f_{n-1}\ \ $ – Bill Dubuque Feb 04 '17 at 14:27
  • Of course, you get a similar matrix version for that $f_n$ with the recurrence $f_{n+1}=(x+y)f_n-xyf_{n-1}$ and thus can be computed with $\begin{pmatrix}0&1\-xy&x+y\end{pmatrix}^n$. @BillDubuque – Thomas Andrews Feb 04 '17 at 15:04
  • @Thomas Yes, that view is in the linked post (though I didn't write out the matrices for that case, it is clear from the example above it, and the linked Fibonacci case). Strangely these very old ideas are not as well-known as they should be, so the more expositions the better. – Bill Dubuque Feb 04 '17 at 15:19