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 (a*b)%c such that (a%c) * (b%c) can be beyond range
- Compute n! under modulo p
- Compute nCr % p | Set 2 (Lucas Theorem)
- Compute sum of digits in all numbers from 1 to n
- Compute nCr % p | Set 3 (Using Fermat Little Theorem)
- 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 maximum of the function efficiently over all sub-arrays
- Compute nCr % p | Set 1 (Introduction and Dynamic Programming Solution)
- Program to compute division upto n decimal places
- Compute power of power k times % m
- Find minimum number to be divided to make a number a perfect square
- Count number of trailing zeros in Binary representation of a number using Bitset
- Count number of triplets with product equal to given number with duplicates allowed