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
- Compute the parity of a number using XOR and table look-up
- Compute n! under modulo p
- Compute (a*b)%c such that (a%c) * (b%c) can be beyond range
- Compute nCr % p | Set 2 (Lucas Theorem)
- Program to compute log a to any base b (logb a)
- Compute nCr % p | Set 3 (Using Fermat Little Theorem)
- Compute sum of digits in all numbers from 1 to n
- Compute average of two numbers without overflow
- Efficient Program to Compute Sum of Series 1/1! + 1/2! + 1/3! + 1/4! + .. + 1/n!
- Compute the maximum power with a given condition
- Compute nCr % p | Set 1 (Introduction and Dynamic Programming Solution)
- Compute maximum of the function efficiently over all sub-arrays
- Program to compute division upto n decimal places
- Compute power of power k times % m
- Number of factors of very large number N modulo M where M is any prime number