Working with NUMBERS[SOLVED] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

13th Feb 2021, 8:12 AM
The Rocky
The Rocky - avatar
5 Answers
+ 2
Add n - rem to N to get N%n as 0
13th Feb 2021, 8:18 AM
Prataparao Sai Vamsi
Prataparao Sai Vamsi - avatar
+ 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.
13th Feb 2021, 8:17 AM
noteve
noteve - avatar
+ 1
Subtract instead of adding
13th Feb 2021, 8:19 AM
Abhay
Abhay - avatar
+ 1
Sorry I forgot to mention that n is fixed and I can only increase N
13th Feb 2021, 8:19 AM
The Rocky
The Rocky - avatar
+ 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
13th Feb 2021, 8:20 AM
Angelo
Angelo - avatar