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
A number is divisible by 9 if…
A number is divisible by 9 if its digits add up to a number divisible by 9
A number is divisible by 7 if…
if a number is divisible 7, then the difference between twice the unit digit of the given number and the remaining part of the given number should be equal to 0, or the multiples of 7.
What is Reminder in following statement?
~~~
Dividend = Divisor x Quotient + Remainder.
~~~
Reminder = Dividend - num;
*num = Largest mulitple of divisor <= Dividend
How to use power function in java?
Math.pow(a, b)
What is return type of Math.pow() in Java?
Double