N corresponds to a string of 8s given by 888888....8888, where N is divisible by 299.
Find the last four digits of the quotient when N is divided by 299.
The sequence of n 8s mod 299 has a period of 66.
So zero 8's is 0 mod 299, as is 66 8s, 132 8's etc.
The function below treats the dividend and quotient as lists of integers, then outputs the dividend and remainder.
('002972872538089929394277220364176885916016350798959494611668524712', 'with remainder', 0)
So the last 4 digits are 4712
This is also true for the multiples of 66:
132:
('002972872538089929394277220364176885916016350798959494611668524712
002972872538089929394277220364176885916016350798959494611668524712', 'with remainder', 0)
198:
('002972872538089929394277220364176885916016350798959494611668524712
002972872538089929394277220364176885916016350798959494611668524712
002972872538089929394277220364176885916016350798959494611668524712', 'with remainder', 0)
--------------------
def large_divide(divisor, dividend):
if type(dividend) == str:
dividend = [int(i) for i in dividend]
elif type(dividend) == int:
dividend = [int(i) for i in str(dividend)]
quotient = []
tempdividend = 0
i=0
for i,v in enumerate(dividend):
tempdividend = tempdividend*10 + dividend[i]
quotient.append(tempdividend // divisor)
tempdividend = tempdividend % divisor
return ''.join([str(j) for j in quotient]), 'with remainder', tempdividend
print(large_divide(299, '8'*66))
print(large_divide(299, '8'*132))
print(large_divide(299, '8'*198))
|
Posted by Larry
on 2023-07-19 16:39:07 |