Following is a factorization program in Python. It works fine till 102030405060708001 but produces incorrect results for greater integers. Why is this so?
import math
a = []
def prime(n):
isPrime = True
for r in range(2,int(n**(1/2)+1)):
if n%r == 0:
isPrime = False
return isPrime
def factor(number):
if prime(number):
a.append(int(number))
for r in range(2, 1 + int(number**(1/2))):
if number%r == 0:
a.append(r)
number = number/r
factor(number)
break
return a
number = int(input("Enter a number whose factors you want:"))
factor(number)
print(f"Factor of {number} are ", end = ": ")
print(*a, sep = ' X ')
print(math.prod(a))
Example Factor of 102030405060708001 are : 1867601 X 54631800401. And the product of these factors is 102030405060708001
Factor of 102030405060708002 are : 2 X 2 X 2 X 2 X 2 X 3 X 3 X 5 X 5 X 5 X 6133 X 462119341. But the product of these factors is 102030405060708000
Factor of 102030405060708003 are : 3 X 2 X 2 X 2 X 2 X 2 X 3 X 5 X 5 X 5 X 6133 X 462119341. But the product of these factors is 102030405060708000