Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/python3
- import sys
- from fractions import gcd
- from itertools import product
- def maximumGcdAndSum(A, B):
- gcd_max=0
- x_max=0
- y_max=0
- for x,y in product(A,B):
- z=gcd(x,y)
- if(z>gcd_max):
- gcd_max=z
- x_max=x
- y_max=y
- elif(z==gcd_max):
- s_new=x+y
- if(s_new>=(x_max+y_max)):
- x_max=x
- y_max=y
- sum=x_max+y_max
- return sum
- if __name__ == "__main__":
- n = int(input().strip())
- list_A = list(map(int, input().strip().split(' ')))
- list_B = list(map(int, input().strip().split(' ')))
- A=list(set(list_A))
- B=list(set(list_B))
- res = maximumGcdAndSum(A, B)
- print(res)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement