Update: I provided an answer but I tried something out with Python and I am kind of surprised. Computer technology today is more advanced than I can wrap my head around.

Instead of taking any residues at all I set my python program to directly add up all the terms in $L$,

$$ \Biggl [\sum_{n=0}^{498}\, \left(2001+2002\, n \right) {(10^{6})}^{n}\Biggl] + 999 \,{(10^{6})}^{499}$$

and then print out $L$. I expected the program to have serious problems number crunching, but it ran in a flash, printing


(use the slider bar)

That was amazing - you can find the remainder by directly dividing $L$ itself and not worrying about inserting any extra residue steps!

I will be going to summer school now to catch up with current technology.

For any $n \ge 1$ with there is a corresponding remainder $r$ obtained by dividing $L$ by $n$.

Now consider only $n$ satisfying

$\tag 1 n \lt 1000000$ $\tag 2 n \notin \{200000, 250000, 333333, 500000, 999999\}$

Calculate an explicit solution $(n,r)$ with $n$ as large as possible.

My Work

I became intrigued examining $L$ after seeing this question and giving an answer.

I think I know the best possible answer $(n,r)$ but it would be interesting to see what mathematics this question sparks; a computer program can be used if necessary for 'mop-up' operations.

  • $\begingroup$ In the title, do you mean find $r \equiv L\pmod{n}$ for $n$ as large as possible? $\endgroup$ – user326210 Jun 23 at 22:20
  • $\begingroup$ @user326210 Yes - from the intent of the question, makes more sense, even though $\equiv$ is symmetric. Changed!. $\endgroup$ – CopyPasteIt Jun 23 at 22:36
  • 1
    $\begingroup$ If you think you know the best answer, but you're not going to tell us what it is, then you are inviting us to waste our time telling you something you already know. $\endgroup$ – Gerry Myerson Jun 23 at 22:57
  • 1
    $\begingroup$ What does "n as large as possible" mean? I would take it to mean $n =999998$. But if that were the case why didn't the question just ask the remainder of $L \mod 999998$? $\endgroup$ – fleablood Jun 24 at 0:08
  • 1
    $\begingroup$ Oh, I thought the challenge was to find a result without using computers to do any of the calculation. 3000-digit numbers are indeed trivial to manipulate with a bignum library (which Python uses spontaneously when results get big enough to need it). $\endgroup$ – Henning Makholm Jun 25 at 9:52

The largest $n$ that satisfies the conditions is $n=999998$, and it shouldn't be too difficult to do that. We're looking for $$ L = 1 + 1000 \sum_{n=0}^{498} (3002+2002n)1000000^n $$ which modulo 999998 is the same as $$ L = 1 + 1000 \sum_{n=0}^{498} ( 3002+2002n) 2^n $$ To calculate this sum, first set $$ X = \sum_{n=0}^{498} 2^n \qquad\qquad Y = \sum_{n=0}^{498}n2^n $$ By standard formulas we get $$ X = \frac{2^{499}-1}{2-1} = 2^{499}-1 $$ and we can find $Y$ by a routine shifting trick: $$ 2Y+2X = Y - 0\cdot 2^0 + 499\cdot 2^{499} $$ or in other words $$ Y = 499\cdot 2^{499} - 2X = 497\cdot 2^{499} + 2 $$ Then $$ L = 1 + 1000(3002X + 2002Y) = 4004001 + 1000\cdot 2^{499}(3002\cdot 499 + 2002\cdot 497) $$ The only real task that remains is to compute $2^{499}$ modulo $999998$. Even with pencil and paper it shouldn't take more than one sheet to compute this by $$ a = 2^{15} = 32768 \\ b = 2^{30} = a^2 \\ c = 2^{31} = 2b \\ d = 2^{62} = c^2 \\ e = 2^{124} = d^2 \\ f = 2^{248} = e^2 \\ g = 2^{249} = 2f \\ h = 2^{498} = g^2 \\ i = 2^{499} = 2h $$ so just eight six-digit squarings or doublings with subsequent reductions modulo $999998$ (which is easy because $1000000\equiv 2$; one doesn't even need to do long division), and then three or four similar arithmetic operations to compute $L$.

I will leave the actual arithmetic to any reader who finds it worth his time.

  • $\begingroup$ A more principled way to reach $2^{499}$ would be to use the Chinese Remainder Theorem, but the only factorization of $999998$ I can find in my head is $2\cdot 499999$, and it's actually easier to reduce modulo $999998$ than $499999$, so that is barely a saving. $\endgroup$ – Henning Makholm Jun 23 at 23:44
  • $\begingroup$ Somehow I thought that powers of $2$ would throw everything into the "I need a quantum computer" - impossible!!! How many atoms in the universe? I didn't check all your steps but accepting your answer and will study later. I never studied the Chinese Remainder Theorem, so I have some work to do! $\endgroup$ – CopyPasteIt Jun 23 at 23:48

Thanks to Henning Makholm and fleablood for helping me see the true power of modular arithmetic - and exponents be damned!

The key idea is you don't want to apply $\text{mod}(n)\text{-Residue}$ to get the remainder of an already big number like $10^{100}$. Instead you use recursion, defining $p_0 = 1$ and for $k \ge 0$,

$$ p_{k+1} = [10^6 \times p_k]\; \text{mod}(n)\text{-Residue}$$

and you can then fold-in $\;p_{100}$ for $10^{100}$ in the remainder calculation.

Here is a python program to calculate remainders for that, now not so scary, large number $L$.


M = 1000000

def bP(i):
    p = 1
    for j in range(0, i):
        p = (p * M) % n
    return p

def getTerm(i):
    return ((2001 + 2002 * i) * bP(i)) % n

while True:
    n = int(input('Please input divisor: '))
    if n == 0:
        raise SystemExit
    r = 0
    for i in range(0, 499):
        r = (r + getTerm(i)) % n
    r = (r + 999 * bP(499)) % n
    print('Divisor =', n, 'Remainder =', r)


Please input divisor: 13
Divisor = 13 Remainder = 6

Please input divisor: 999998
Divisor = 999998 Remainder = 487763

Please input divisor: 59470
Divisor = 59470 Remainder = 42391

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.