Advertisement
UF6

1.3 and 1.4 Problem 12/9

UF6
Jun 17th, 2016
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. #12
  2. def gcd(x, y):
  3.     while y != 0:
  4.         (x, y) = (y, x % y)
  5.     return x
  6.  
  7.  
  8. #9
  9. def prime(n):
  10.     primefactor = []
  11.     d = 2
  12.     while d*d <= n:
  13.         while (n % d) == 0:
  14.             primefactor.append(d)
  15.             n //= d
  16.         d += 1
  17.     if n > 1:
  18.        primefactor.append(n)
  19.     return primefactor
  20.  
  21.  
  22. def testGCD(a,b):
  23.     pass
  24.    
  25. d=gcd(10, 4)
  26. print ("gcd(10, 4)= ", d, 10/d, 4/d)
  27.  
  28. print( gcd(4,10))
  29.  
  30. def testPrime(n):
  31.    factors = prime(n)
  32.    print( "the prime factors of %d are"%(n), factors)
  33.    prod = 1
  34.    for f in factors:
  35.        prod *= f
  36.    print("Their product is ", prod)
  37.  
  38.  
  39. testPrime(360)
  40. testPrime(123456789)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement