aboutsummaryrefslogtreecommitdiff
path: root/lib/fact.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fact.py')
-rw-r--r--lib/fact.py48
1 files changed, 24 insertions, 24 deletions
diff --git a/lib/fact.py b/lib/fact.py
index ba961c4..2beb0cb 100644
--- a/lib/fact.py
+++ b/lib/fact.py
@@ -3,35 +3,35 @@
import sys
import math
-error = 'fact.error' # exception
+error = 'fact.error' # exception
def fact(n):
- if n < 1: raise error # fact() argument should be >= 1
- if n = 1: return [] # special case
- res = []
- _fact(n, 2, res)
- return res
+ if n < 1: raise error # fact() argument should be >= 1
+ if n = 1: return [] # special case
+ res = []
+ _fact(n, 2, res)
+ return res
def _fact(n, lowest, res):
- highest = int(math.sqrt(float(n+1)))
- for i in range(lowest, highest+1):
- if n%i = 0:
- res.append(i)
- _fact(n/i, i, res)
- break
- else:
- res.append(n)
+ highest = int(math.sqrt(float(n+1)))
+ for i in range(lowest, highest+1):
+ if n%i = 0:
+ res.append(i)
+ _fact(n/i, i, res)
+ break
+ else:
+ res.append(n)
def main():
- if len(sys.argv) > 1:
- for arg in sys.argv[1:]:
- n = eval(arg)
- print n, fact(n)
- else:
- try:
- while 1:
- print fact(input())
- except EOFError:
- pass
+ if len(sys.argv) > 1:
+ for arg in sys.argv[1:]:
+ n = eval(arg)
+ print n, fact(n)
+ else:
+ try:
+ while 1:
+ print fact(input())
+ except EOFError:
+ pass
main()