#include <bits/stdc++.h>
using namespace std;
const int A = 100000, MD = 998244353;
int kk[A + 1];
int pp[A + 1][6][6], aa[6][6], tt[6][6];
int uu_[6], vv_[6], *uu = uu_, *vv = vv_;
int kp[A + 1];
bool sq[A + 1];
void init(int *aa, int a0, int a1, int a2, int a3, int a4, int a5) {
  aa[0] = a0, aa[1] = a1, aa[2] = a2, aa[3] = a3, aa[4] = a4, aa[5] = a5;
}
void init(int aa[][6], int x) {
  int x2 = x * 2 % MD;
  int xx = (long long)x * x % MD;
  init(aa[0], 2, 1, x2, x2, xx, xx);
  init(aa[1], 0, 2, 0, x2, 0, xx);
  init(aa[2], 0, 0, 2, 1, x, x);
  init(aa[3], 0, 0, 0, 2, 0, x);
  init(aa[4], 0, 0, 0, 0, 2, 1);
  init(aa[5], 0, 0, 0, 0, 0, 2);
}
void mult(int aa[][6], int *uu, int *vv) {
  for (int i = 0; i < 6; i++) {
    long long v = 0;
    for (int j = i; j < 6; j++) v += (long long)aa[i][j] * uu[j];
    vv[i] = v % MD;
  }
}
void mult(int aa[][6], int bb[][6], int cc[][6]) {
  for (int i = 0; i < 6; i++)
    for (int j = i; j < 6; j++) {
      long long c = 0;
      for (int k = i; k <= j; k++) c += (long long)aa[i][k] * bb[k][j];
      cc[i][j] = c % MD;
    }
}
void power(int aa[][6], int pp[][6], int tt[][6], int k) {
  if (k == 1) {
    for (int i = 0; i < 6; i++)
      for (int j = i; j < 6; j++) pp[i][j] = aa[i][j];
    return;
  }
  if (k == 2) {
    mult(aa, aa, pp);
    return;
  }
  if (k & 1) {
    power(aa, pp, tt, k >> 1);
    mult(pp, pp, tt);
    mult(tt, aa, pp);
  } else {
    power(aa, tt, pp, k >> 1);
    mult(tt, tt, pp);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int m;
  cin >> m;
  while (m--) {
    int a, k;
    cin >> a >> k;
    kk[a] = k;
    init(aa, a);
    power(aa, pp[a], tt, k);
  }
  long long ans = 0;
  for (int a = 1; a <= A; a++) {
    if (sq[a]) continue;
    if (a > 1 && kp[a] == 0) {
      for (int b = a; b <= A; b += a) kp[b]++;
      if (a <= A / a)
        for (int s = a * a, t = s; t <= A; t += s) sq[t] = true;
    }
    fill(uu, uu + 6, 0);
    uu[5] = 1;
    for (int b = a; b <= A; b += a)
      if (kk[b] > 0) {
        mult(pp[b], uu, vv);
        swap(uu, vv);
      }
    int z = uu[0] - uu[1];
    ans += kp[a] % 2 == 0 ? z : -z;
  }
  ans %= MD;
  if (ans < 0) ans += MD;
  cout << ans << '\n';
  return 0;
}
