avkLab

PGCD-PPCM

Jun 11th, 2022
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #----------------------------------------------------------------------------
  4. # Created by  : Alain Van Kerckhoven
  5. # Created Date: 18 juillet 2016
  6. # Licence     : GPL
  7. # Version     : 1.0
  8. # ---------------------------------------------------------------------------
  9. """
  10. Calcule les diviseurs communs de deux nombres, leur PGCD et leur PPCM (avec tuples)
  11. """
  12. # ---------------------------------------------------------------------------
  13.  
  14. def findDivisors(n1, n2):
  15.     divisors = ()
  16.     for i in range(1, min(n1, n2) + 1):
  17.         if n1%i == 0 and n2%i == 0:
  18.             divisors = divisors + (i,)
  19.     return divisors
  20.  
  21. num1 = int(input("Premier nombre : "))
  22. num2 = int(input("Second nombre : "))
  23.  
  24. divisors = findDivisors(num1, num2)
  25. pgcd = max(divisors)
  26. ppcm = int(num1*num2/pgcd)
  27.  
  28. print("Diviseurs communs :", divisors)
  29. print("PGCD :", pgcd)
  30. print("PPCM :", ppcm)
  31.  
Advertisement
Add Comment
Please, Sign In to add comment