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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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
- Program to compute log a to any base b (logb a)
- 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
- Compute average of two numbers without overflow
- Compute the maximum power with a given condition
- 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
- Number of factors of very large number N modulo M where M is any prime number
- Find the largest number smaller than integer N with maximum number of set bits
- Minimum number of distinct powers of 2 required to express a given binary number
- Find minimum number to be divided to make a number a perfect square
- Count number of triplets with product equal to given number with duplicates allowed
- Count number of trailing zeros in Binary representation of a number using Bitset