#include <bits/stdc++.h>
#include <cwchar>
#define speed \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define ll long long
#define YES "Yes"
#define NO "No"
#define endline '\n'
using namespace std;
const ll N = 1e6 + 10, MM = 1e9 + 7, MAX = 1e18;
ll mxCost[N], f[N], p[N];
ll k;
ll res;
int solve() {
int n;
cin >> n;
cin >> k;
for (int i = 1; i < N; i++)
f[i] = -1;
set<ll> s;
for (int i = 0; i < n; i++) {
ll x;
cin >> x;
ll y;
cin >> y;
if (x > 1e6)
continue;
s.insert(x);
for (int j = x; j * j <= k; j += x) {
if (mxCost[j] == -1)
continue;
if (j / x % x == 0)
mxCost[j] = -1;
mxCost[j] = max(mxCost[j], y);
f[j] *= -1;
p[j] = x;
}
}
for (int i = 2; i * i <= k; i++) {
ll x=i;
while(p[x]){
x/=p[x];
}
if(x>1)continue;
res += k / i / i * f[i] * mxCost[i];
}
cout << res << endline;
return 0;
}
int main() {
speed;
int t = 1;
// cin >> t;
int i = 1;
while (t--) {
// cout << "Case #" << i++ << ": ";
solve();
}
return 0;
}
/*
*/
Copy