Given a big number ‘num’ represented as string and an integer x, find value of “num % x” or “num mod x”. Output is expected as an integer.
Input: num = "12316767678678", a = 10 Output: num (mod a) ≡ 8
The idea is to process all digits one by one and use the property that xy (mod a) ≡ ((x (mod a) * y) (mod a)). Below is the implementation.
Thanks to utkarsh111 for suggesting the below solution.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Number Theory (Interesting Facts and Algorithms)
- Divide large number represented as string
- Multiply large integers under large modulo
- Modulo 10^9+7 (1000000007)
- Find sum of modulo K of first N natural number
- Find (a^b)%m where 'a' is very large
- Find Last Digit of a^b for Large Numbers
- Stein's Algorithm for finding GCD
- GCD of two numbers when one of them can be very large
- How to avoid overflow in modular multiplication?
- Modular Exponentiation (Power in Modular Arithmetic)
- Euclidean algorithms (Basic and Extended)
- Factorial of a large number
- Efficient program to print all prime factors of a given number
- Sieve of Eratosthenes