function Main(input) { const [[N, W], X, Y] = input.split("\n").map(e => e.split(" ").map(Number)); const max = 2e5; let price = [...new Array(max + 1).fill(0)]; for (let i = 0; i < N; i++) { const set = new Set(); const num = X[i]; for (let j = 1; j <= Math.sqrt(num); j++) { if (num % j === 0) { set.add(j); set.add(num / j); } } for (const v of [...set]) { price[v] += Y[i]; } } let ans = 0; for (let i = W; i <= max; i++) { ans = Math.max(price[i], ans); } console.log(ans); } Main(require("fs").readFileSync(0)+"")