-1
$\begingroup$

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?

  • 0
    I don't think you are correct when you say "If $P$ is a multiple of $2$ or $5$, it will always be $1$." If $P=2$ or $P=5$, it will be $1$, but not true for multiples.2017-02-03
  • 0
    [Here](http://math.stackexchange.com/a/2128037/242) it is remarked this is from an ongoing [code chef contest](https://www.codechef.com/FEB17/problems/KBIGNUMB)2017-02-03

1 Answers 1

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}$$

  • 0
    @ThomasAndrews Thanks a lot. But I found this question as a duplicate.. deleting..2017-02-03
  • 1
    @ThomasAndrews Yes certainly. http://stackoverflow.com/a/9486650/61515972017-02-03
  • 0
    Yes thanks a lot for your hardwork. Its perfect!2017-02-03
  • 0
    @Thomas Seems to be Code Chef contest problem, see my comment on the question.2017-02-03
  • 0
    Yes, so I see. Ugh. Disappointing since I enjoyed the problem so much. @BillDubuque2017-02-03
  • 0
    @Thomas I definitely sympathize. Nice answer +12017-02-03
  • 0
    I think my shorter "hint" answer is even better - more math-y, less programmy. :)2017-02-03
  • 0
    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)2017-02-03
  • 1
    Readers may also find of interest the general [addition law](http://math.stackexchange.com/a/1867085/242) 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}\ \ $2017-02-04
  • 0
    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$. @BillDubuque2017-02-04
  • 0
    @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.2017-02-04