aboutsummaryrefslogtreecommitdiff
path: root/code/python/naive.py
blob: 7f6ec008f971e96576a4f05a500653bada1c93e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/env python

from sys import argv
from math import floor, sqrt

def naive_factor(n: int) -> int:
	for i in range(2,floor(sqrt(n))+1):
		if n%i == 0:
			return i
	else:
		return -1

N = int(argv[-1])
f = naive_factor(N)
if f == -1:
	print(N, "is prime")
else:
	print(N, "=", f, "*", N//f)

Generated with cgit - Back to sebastiano.tronto.net