ಗಣಿತ ಸಮಸ್ಯೆಯನ್ನು ಬಗೆಹರಿಸಿ
ಈ ರೀತಿಯಾಗಿ ಕೋಟ್ಯಂತರ ವಿಧಾನಗಳನ್ನು ಬಳಸಲಾಗುತ್ತದೆ.
ಅಡಿಯಿಡು (step)
- 3^{100} \bmod 7
Never compute the huge power. Reduce after every multiplication (repeated squaring).
- 3 \equiv 3 \pmod{7}
Reduce the base first.
- 100 = 1100100_2
Write the exponent in binary: 7 squarings at most.
- 3^2 \equiv 2 \pmod{7}
Square the running power.
- 2^2 \equiv 4 \pmod{7}
Square the running power.
- r \leftarrow r \cdot 4 \equiv 4 \pmod{7}
This bit is 1: multiply the result by the current power.
- 4^2 \equiv 2 \pmod{7}
Square the running power.
- 2^2 \equiv 4 \pmod{7}
Square the running power.
- 4^2 \equiv 2 \pmod{7}
Square the running power.
- r \leftarrow r \cdot 2 \equiv 1 \pmod{7}
This bit is 1: multiply the result by the current power.
- 2^2 \equiv 4 \pmod{7}
Square the running power.
- r \leftarrow r \cdot 4 \equiv 4 \pmod{7}
This bit is 1: multiply the result by the current power.
- 3^{100} \equiv 4 \pmod{7}
Done.