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.
- Count number of solutions of x^2 = 1 (mod p) in given range
- Program for quotient and remainder of big number
- Prime factors of a big number
- Divide a big number into two parts that differ by k
- Find power of power under mod of a prime
- Find value of (1^n + 2^n + 3^n + 4^n ) mod 5
- Find value of y mod (2 raised to power x)
- Find value of (n^1 + n^2 + n^3 + n^4) mod 5 for given n
- Trick for modular division ( (x1 * x2 .... xn) / b ) mod (m)
- Divide two integers without using multiplication, division and mod operator | Set2
- Minimum steps to reach end from start by performing multiplication and mod operations with array elements
- Value of the series (1^3 + 2^3 + 3^3 + ... + n^3) mod 4 for a given n
- Find (1^n + 2^n + 3^n + 4^n) mod 5 | Set 2
- Sorting Big Integers
- Compute the parity of a number using XOR and table look-up
- Compute n! under modulo p
- Compute sum of digits in all numbers from 1 to n
- Compute nCr % p | Set 1 (Introduction and Dynamic Programming Solution)
- Compute nCr % p | Set 2 (Lucas Theorem)
- Compute (a*b)%c such that (a%c) * (b%c) can be beyond range