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
- Find Last Digit of a^b for Large Numbers
- Find (a^b)%m where ‘a’ is very large
- Modulo 10^9+7 (1000000007)
- GCD of two numbers when one of them can be very large
- Stein’s Algorithm for finding GCD
- Number of Permutations such that no Three Terms forms Increasing Subsequence
- Check if the first and last digit of the smallest number forms a prime
- Print all substring of a number without any conversion
- Complement of a number with any base b
- Check if Decimal representation of an Octal number is divisible by 7