Modular arithmetic Flashcards
What is 72%7 ?
2
What is -19%8 ?
5
What is range of a%m?
[0, m-1]
What is -60%9 in python ?
3
What is -60%9 in c/c++/java/js/c# ?
-6 (In case of these language to calculate correct a%m add m to the answer so -6+9 = 3(correct ans))
Why do we need modular arithmetic?
It’s is used is concepts like consistent hashing, hash table, encryption etc.
True or False
((a+b)%m) == (a%m + b%m)
False eg. (7+7)%4
True or False
((a+b)%m) == (a%m + b%m)%m
True
True or False
(a*b)%m == ((a%m)*(b*m))%m
True
Which number is divisible by 3?
* 4351
* 3521
* 7326
* 8236
7326
*sum of all digits should be divisible by 3.
Which number is dvisible by 4?
* 42234
* 64262
* 87118
* 43256
43256
*Last two digit should be divisible by 4.
What is 534259%3 ?
1
*(Sum of all the digits)%3
What is 63493%4 ?
1
*(Last two digits) % 4
A number is divisible by 8 if….
A number is divisible by 8 if its last three digits are divisible by 8.
A number is divisible by 6 if…
A number is divisible by 6 if it is divisible by 2 and 3