Listato Python

 

Output

#!/usr/bin/env python
#file scomposizioni.py

import sys
import math

def nprimo (a):
    primo=False
    npr=a+2
    while (primo==False):
      
      c=npr-1
      for i in range (2,c):
          if (npr%i==0):
                      i=c
                      npr=npr+2
                      primo=False
                      
          else:
              primo=True
    return (npr)


print ("Scomposizione in fattori primi di un numero")
print ()
n= int(input ("Dammi il numero "))
r=0
i=2
while (r == 0):
   r = n % i
   if (r == 0):
       print ('%8d %7d' % (n,i))
       n = n//i

if (n != 0):
    r=0
    i=3
    while (r == 0):
      r = n % i
      if (r == 0):
         print ('%8d %7d' % (n,i))
         n = n//i      

np=3
while (n > 1):
   if (n != 0):
      r=0
      p = nprimo(np)
      while (r == 0):
         r = n % p
         if (r == 0):
            print ('%8d %7d' % (n,p))
            n = n//p
      np=np+2
print ('%8d' % (n))