← Back to Games

✨ Magical Mod Arena

Binary exponentiation with modulo - O(log N) power!

🔮 Power Calculation
210 mod 1000
?
📊 Exponent in Binary (process right to left)
📜 Calculation Steps
Ready Enter values and calculate...

📚 Binary Exponentiation (Fast Power)

Calculate ab mod m in O(log b) time using bit manipulation!

result = 1 while (exp > 0): if (exp & 1): // If last bit is 1 result = (result * base) % mod base = (base * base) % mod // Square exp = exp >> 1 // Right shift (divide by 2)

Key insight: Any number can be expressed as sum of powers of 2.
Example: 210 = 28 × 22 (since 10 = 1010 in binary)