From 7f1b8a358515b45d717c3c4b5baf2fbc0f568170 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Wed, 26 Feb 2025 17:12:06 +0100 Subject: Initial commit --- code/python/naive.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 code/python/naive.py (limited to 'code/python/naive.py') 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 @@ +#!/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) -- cgit v1.3