Devise an algorithm that determines whether a given positive integer N is divisible by 13, and if NOT, to find the remainder.
N can contain up to 20,220 digits.
Note: Simply dividing by 13 or, performing long division by 13 is NOT permissible.
(In reply to
re: No Subject by Charlie)
I originally had:
if temp%13 == 0:
return True
else:
return False
But added the other since it asks for the remainder.
Or you could end with
if temp%13 == 0:
return temp%13
else:
return temp%13
Which gives the remainder only.
But I think the main point is, is it ok to divide a small number by 13? I would assume that the intent was to not divide a huge number by 13, but OK to divide a small number by 13. If this is not the case then repeated subtraction of 13 seemingly would be OK stopping when you get to a number from 0 to 13. (or adding 13 if you start out with a negative small number).
|
Posted by Larry
on 2022-04-15 14:07:28 |