+ 1
Working with NUMBERS[SOLVED]
#given a number N=int(input()) #I want to check if it is divisible for another number n (example N=20, n=3) Rem= 20%3 - >2 #NOW, I want to add to N that number which makes the remainder =0. #If I add the Rem to N I still get (20+2 %3 - >1) How can I do it? Thanks
5 odpowiedzi
+ 2
Add n - rem to N to get N%n as 0
+ 4
You need a condition, if it has remainder then N is not divisible by n, if the remainder is 0 then N is divisible by n.
For example:
20 % 3 == 2
This has remainder 2 therefore 20 is not divisible by 3.
21 % 3 == 0
This has no remainder therefore 21 is divisible by 3.
+ 1
Subtract instead of adding
+ 1
Sorry I forgot to mention that n is fixed and I can only increase N
+ 1
You should either subtract the reminder or add its additive inverse
if a = b(mod n) than a-b=0(mod n)
The same way as
if a=b than a-b=0