Created
February 7, 2019 19:19
-
-
Save Ph0enixKM/a6e8bfc829d289ab86aa8ea2df30cf1b to your computer and use it in GitHub Desktop.
Counts number factors in a file where numbers are separated with ('\n')s
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
file = open("liczby.txt") | |
liczby = [int(i) for i in file.readlines()] | |
czynniki = [[]] | |
def pierwsza(liczba): | |
counts = 0 | |
for i in range(1, liczba): | |
if (liczba % i == 0): | |
counts += 1 | |
if (counts > 3): | |
return False | |
return True | |
def factors(liczby): | |
for i, liczba in enumerate(liczby): | |
while (liczba != 1): | |
szukana = 2 | |
while (szukana <= liczba): | |
if (pierwsza(int(szukana)) and (liczba % szukana == 0)): | |
czynniki[i].append(szukana) | |
liczba /= szukana | |
szukana = 2 | |
if (liczba <= 1): | |
break | |
if (szukana > 10000): | |
# Żeby przeskoczyć wielkie liczby | |
szukana = int(liczba) | |
continue | |
szukana += 1 | |
print(czynniki[i]) | |
temp = [] | |
for j in czynniki[i]: | |
if (not j in temp): | |
temp.append(j) | |
if (len(temp) == 3): | |
print("TAK") | |
else: | |
print("NIE") | |
czynniki.append([]) | |
factors(liczby) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment