from math import gcd from collections import defaultdict def divisors(x): ret = [] i = 1 while (i**2 <= x): if x%i == 0: ret.append(i) if i != x//i: ret.append(x//i) i += 1 return ret n,w = map(int,input().split()) x = list(map(int,input().split())) y = list(map(int,input().split())) d = defaultdict(int) for xi,yi in zip(x,y): for p in divisors(xi): d[p] += yi ans = 0 for ky,vl in d.items(): if ky >= w: ans = max(vl,ans) print(ans)