Problem p01560 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define dump(n) cout << "# " << #n << '=' << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define peri(i, a, b) for (int i = int(b); i-- > int(a);)
#define rep(i, n) repi(i, 0, n)
#define per(i, n) peri(i, 0, n)
#define all(c) begin(c), end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const ll INF = 2e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '(' << p.first << ',' << p.second << ')';
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
  os << '[';
  rep(i, a.size()) os << (i ? " " : "") << a[i];
  return os << ']';
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
  if (a == INF || b == INF)
    return INF;
  if (a / gcd(a, b) > INF / b)
    return INF;
  return a / gcd(a, b) * b;
}

int main() {
  for (ll n, m; cin >> n >> m && n | m;) {
    vl as(n);
    rep(i, n) cin >> as[i];
    vd ps(n);
    rep(i, n) cin >> ps[i], ps[i] /= 100;

    // f(S): -1^|S| × (Sのどの要素でも割り切れる1<=x<=mの個数)
    // g(S): Sのいずれかの要素で割り切れる1<=x<=mの個数
    vl f(1 << n);
    repi(i, 1, 1 << n) {
      ll l = 1;
      rep(j, n) if (i >> j & 1) l = lcm(l, as[j]);
      if (l == INF)
        continue;

      int sign = __builtin_popcount(i) & 1 ? 1 : -1;
      f[i] += sign * m / l;
    }
    vl g = f;
    rep(i, n) rep(j, 1 << n) if (j >> i & 1) g[j] += g[j ^ 1 << i];

    double res = 0;
    repi(i, 1, 1 << n) {
      double p = 1;
      rep(j, n) p *= i >> j & 1 ? ps[j] : 1 - ps[j];
      res += p * g[i];
    }
    printf("%.10f\\n", res);
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define dump(n) cout << "# " << #n << '=' << (n) << endl
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define peri(i, a, b) for (int i = int(b); i-- > int(a);)
#define rep(i, n) repi(i, 0, n)
#define per(i, n) peri(i, 0, n)
#define all(c) begin(c), end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const ll INF = 2e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '(' << p.first << ',' << p.second << ')';
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) {
  os << '[';
  rep(i, a.size()) os << (i ? " " : "") << a[i];
  return os << ']';
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
  if (a == INF || b == INF)
    return INF;
  if (a / gcd(a, b) > INF / b)
    return INF;
  return a / gcd(a, b) * b;
}

int main() {
  for (ll n, m; cin >> n >> m && n | m;) {
    vi as(n);
    rep(i, n) cin >> as[i];
    vd ps(n);
    rep(i, n) cin >> ps[i], ps[i] /= 100;

    // f(S): -1^|S| × (Sのどの要素でも割り切れる1<=x<=mの個数)
    // g(S): Sのいずれかの要素で割り切れる1<=x<=mの個数
    vl f(1 << n);
    repi(i, 1, 1 << n) {
      ll l = 1;
      rep(j, n) if (i >> j & 1) l = lcm(l, as[j]);
      if (l == INF)
        continue;

      int sign = __builtin_popcount(i) & 1 ? 1 : -1;
      f[i] += sign * m / l;
    }
    vl g = f;
    rep(i, n) rep(j, 1 << n) if (j >> i & 1) g[j] += g[j ^ 1 << i];

    double res = 0;
    repi(i, 1, 1 << n) {
      double p = 1;
      rep(j, n) p *= i >> j & 1 ? ps[j] : 1 - ps[j];
      res += p * g[i];
    }
    printf("%.10f\\n", res);
  }
}