aboutsummaryrefslogtreecommitdiff
path: root/code/python/naive.py
diff options
context:
space:
mode:
Diffstat (limited to 'code/python/naive.py')
-rwxr-xr-xcode/python/naive.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/code/python/naive.py b/code/python/naive.py
new file mode 100755
index 0000000..7f6ec00
--- /dev/null
+++ b/code/python/naive.py
@@ -0,0 +1,18 @@
1#!/bin/env python
2
3from sys import argv
4from math import floor, sqrt
5
6def naive_factor(n: int) -> int:
7 for i in range(2,floor(sqrt(n))+1):
8 if n%i == 0:
9 return i
10 else:
11 return -1
12
13N = int(argv[-1])
14f = naive_factor(N)
15if f == -1:
16 print(N, "is prime")
17else:
18 print(N, "=", f, "*", N//f)

Generated with cgit - Back to sebastiano.tronto.net