Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #!/bin/python3
  2.  
  3. import sys
  4. from fractions import gcd
  5. from itertools import product
  6.  
  7. def maximumGcdAndSum(A, B):
  8. gcd_max=0
  9. x_max=0
  10. y_max=0
  11. for x,y in product(A,B):
  12. z=gcd(x,y)
  13. if(z>gcd_max):
  14. gcd_max=z
  15. x_max=x
  16. y_max=y
  17. elif(z==gcd_max):
  18. s_new=x+y
  19. if(s_new>=(x_max+y_max)):
  20. x_max=x
  21. y_max=y
  22. sum=x_max+y_max
  23. return sum
  24.  
  25. if __name__ == "__main__":
  26. n = int(input().strip())
  27. list_A = list(map(int, input().strip().split(' ')))
  28. list_B = list(map(int, input().strip().split(' ')))
  29. A=list(set(list_A))
  30. B=list(set(list_B))
  31. res = maximumGcdAndSum(A, B)
  32. print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement