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 3 (Using Fermat Little Theorem)
- Compute nCr % p | Set 2 (Lucas Theorem)
- Compute sum of digits in all numbers from 1 to n
- Efficient Program to Compute Sum of Series 1/1! + 1/2! + 1/3! + 1/4! + .. + 1/n!
- Compute average of two numbers without overflow
- 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
- Count number of triplets with product equal to given number with duplicates allowed
- Find minimum number to be divided to make a number a perfect square
- Querying maximum number of divisors that a number in a given range has
- Count number of digits after decimal on dividing a number