Number theory: prove the step, bound the value
- Euclid preserves common divisors.
- LCM needs a representable result or an explicit overflow outcome.
- Binary exponentiation preserves a product modulo m.
- The sieve counts primes strictly below n.
1 / 8
a=q*b+r: divisors of (a,b) equal divisors of (b,r).
(84,30) → (30,24) → (24,6) → (6,0)
The positive second argument decreases; return 6.
For [6,10,15]:
| Prefix | GCD | LCM |
|---|---|---|
[6] |
6 | 6 |
[6,10] |
2 | 30 |
[6,10,15] |
1 | 30 |
LCM uses gcd(currentLCM,value), not the prefix GCD.
MAX=9_223_372_036_854_775_807.q=currentLCM/gcd(currentLCM,v).q > MAX/v with integer division before multiplying.-1; continue computing exact GCD.Invariant: result*x^e ≡ originalBase^originalExponent (mod m).
For 5^13 mod 23, states (result,x,e) are:
(1,5,13) → (5,2,6) → (5,4,3) → (20,16,1) → (21,3,0).
Odd: multiply result. Every step: square x and halve e.
result=1 mod m, so exponent zero with m=1 returns 0.m <= 1_000_000_007; reduced products fit signed 64-bit.For n=12, allocate indices 0..11.
n=11 instead excludes 11 and returns 4.