-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbetterrsa
More file actions
executable file
·45 lines (28 loc) · 910 Bytes
/
betterrsa
File metadata and controls
executable file
·45 lines (28 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
from sys import argv, exit
from math import sqrt
def read_test_file(file_name):
"""Function to read number from file: one number per file"""
with open(file_name, "r", encoding="utf-8") as file:
lines = file.readlines()
number_to_factor = []
for line in lines:
# Check if the number has 100 or more digits
n = int(line.strip())
if n >= 10**99:
print(100)
exit(100)
number_to_factor.append(n)
return number_to_factor
def find_numbers(n):
"""Function to find factors of current number"""
for i in range(1, n):
if n == ((n // i) * i):
print("{}={}*{}".format(n, (n // i), i))
break
def factors(ls):
"""Function to iterate between numbers in file"""
for i in ls:
find_numbers(i)
if len(argv) == 2:
factors(read_test_file(argv[1]))