There is no need for a brute force search. There is also no need for compilation, which may run into the maximum compiled integer limit. A faster solution follows from a bit of theory. You can get the first 225000 solutions (up to $n\approx 306$ billion) in less than a second.

The original equation is ${\rm Mod}[10^{6n+5}-54n-46,p]=0$, where $p=1355297$.

Let $m=6n+5$ and write the equation as `PowerMod[10,m,p]=Mod[9m+1,p]`

.

The period of the cycle of `PowerMod[10,x,p]`

for $x=1,2,3,...$ equals the period of the decimal expansion of $1/p$, for prime $p$. The length of the repeating decimal of $1/p$ is `MultiplicativeOrder[10,p]`

which, in this case, equals $p-1$.

```
MultiplicativeOrder[10, 1355297]
```

1355296

These are all 1355296 distinct residues in the repeating cycle. This pre-calculation takes about 3/4 second.

```
residues = PowerMod[10, Range[1355296], 1355297]
```

The two modular equations are:

$m=i+j*(p-1)$, mod $p$, with $1\le i \le p-1$, and $j\ge 1$, from length-$(p-1)$ cycle of residues for `PowerMod[10,m,p]`

$9m+1=k*p+r_i$, mod $p$, with $0\le k$, from `Mod[9m+1,p]=ri`

, the i'th residue.

Multiply the first equation by 9 and equate to give $a*j+b*k=c$, where $a=9*(p-1)$, $b=-p$, and $c=r_i-1-9*i$. Solve this linear Diophantine equation via `ExtendedGCD[a,b]`

.

```
ExtendedGCD[9(p-1),-p]={g,{u,v}}
```

{1, {301177, 2710591}}

Only the first term, $u=301177$, of the second part is required.

There are infinitely many solutions $\{j,k\}=\{u*c+b*q,v*c-a*q\}$, where $q\ge $0 and $a*u+b*v=1$ is found via `ExtendendGCD[a,b]`

. The smallest solution occurs when `q=Quotient[u*c,p]`

. The last step is to sort those solutions $m$ equivalent to 5, mod 6.

The first roughly quarter million solutions are found in about 1/4 second. The fastest of the current 3 answers was from @MichaelE2, where the first 10 solutions are found in about 0.68 s.

```
Block[{p = 1355297, i, u, uc},
u = ExtendedGCD[9 (p - 1), -p][[2, 1]];
AbsoluteTiming[
i = Range[Length[residues]];
uc = u*(residues[[i]] - 1 - 9 i);
(Sort[Pick[#, Mod[#, 6], 5] &[i + (p - 1) (uc - p*Quotient[uc, p])]] - 5)/6
]]
```

{0.230856, {2331259, 3776127, 5366598, 5505709, 5652052, 7317951,...,
306133783114, 306135079824, 306136273333}}

Subsequent solutions follow by decreasing the integer `q=Quotient[uc,p]`

.

What did you try in MMA? – Ulrich Neumann – 2018-02-09T09:59:19.190

2@Ulrich What is MMA ? – Bobby H – 2018-02-09T10:00:28.287

Sorry, Mathematica – Ulrich Neumann – 2018-02-09T10:12:00.210

1O yes I am quite sure that $1355297$ divides $(10^{1836828602912}-9*1836828602911-10)$. I calculated this with my calculator. – Bobby H – 2018-02-09T10:33:39.477

Where does this question originate from? – Chip Hurst – 2018-02-09T16:14:42.063