You are viewing a single comment's thread. Return to all comments →
Yeah thats not nice... Your approach using lists and all() is much more elegant.
n,m = map(int, input().strip().split(' '))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ausgabe = 0
for q in range(max(a), min(b) +1):
if all(q % arr == 0 for arr in a) and all(brr % q == 0 for brr in b):
ausgabe += 1
amazing way, but would this be O^2 ??
i think its O(2n^2)
O(2n^2) is supposed to be O(n^2). Constants aren't taken into account.
Asymptomatic complexity... i think now i got it :D
It's asymptotic actually :)
:D I knew it was something like that.
can you test this i/p:
4 8 12
print(len([num for num in range(max(a),max(b)+1) if (all(num%i==0 for i in a)) and all(i%num==0 for i in b)]))
surely should be min(b)+1 not max(b)+1
Awesome solution !!