description: Kuzya started going to school. He was given math homework in which he was given an array a of length n and an array of symbols b of length n, consisting of symbols '*' and '/'.
  
  Let's denote a path of calculations for a segment [l; r] (1 ≤ l ≤ r ≤ n) in the following way: 
  
    * Let x=1 initially. For every i from l to r we will consequently do the following: if b_i= '*', x=x*a_i, and if b_i= '/', then x=(x)/(a_i). Let's call a path of calculations for the segment [l; r] a list of all x that we got during the calculations (the number of them is exactly r - l + 1). 
  
  
  
  For example, let a=[7, 12, 3, 5, 4, 10, 9], b=[/, *, /, /, /, *, *], l=2, r=6, then the path of calculations for that segment is [12, 4, 0.8, 0.2, 2].
  
  Let's call a segment [l;r] simple if the path of calculations for it contains only integer numbers. 
  
  Kuzya needs to find the number of simple segments [l;r] (1 ≤ l ≤ r ≤ n). Since he obviously has no time and no interest to do the calculations for each option, he asked you to write a program to get to find that number!
  
  Input
  
  The first line contains a single integer n (2 ≤ n ≤ 10^6).
  
  The second line contains n integers a_1, a_2, …, a_n (1 ≤ a_i ≤ 10^6).
  
  The third line contains n symbols without spaces between them — the array b_1, b_2 … b_n (b_i= '/' or b_i= '*' for every 1 ≤ i ≤ n).
  
  Output
  
  Print a single integer — the number of simple segments [l;r].
  
  Examples
  
  Input
  
  
  3
  1 2 3
  */*
  
  
  Output
  
  
  2
  
  
  Input
  
  
  7
  6 4 10 1 2 15 1
  */*/*//
  
  
  Output
  
  
  8
solution: #include <bits/stdc++.h>
  using namespace std;
  using ll = long long;
  using ld = long double;
  template <typename T>
  vector<T>& operator--(vector<T>& v) {
    for (auto& i : v) --i;
    return v;
  }
  template <typename T>
  vector<T>& operator++(vector<T>& v) {
    for (auto& i : v) ++i;
    return v;
  }
  template <typename T>
  istream& operator>>(istream& is, vector<T>& v) {
    for (auto& i : v) is >> i;
    return is;
  }
  template <typename T>
  ostream& operator<<(ostream& os, vector<T> v) {
    for (auto& i : v) os << i << ' ';
    return os;
  }
  template <typename T, typename U>
  pair<T, U>& operator--(pair<T, U>& p) {
    --p.first;
    --p.second;
    return p;
  }
  template <typename T, typename U>
  pair<T, U>& operator++(pair<T, U>& p) {
    ++p.first;
    ++p.second;
    return p;
  }
  template <typename T, typename U>
  istream& operator>>(istream& is, pair<T, U>& p) {
    is >> p.first >> p.second;
    return is;
  }
  template <typename T, typename U>
  ostream& operator<<(ostream& os, pair<T, U> p) {
    os << p.first << ' ' << p.second;
    return os;
  }
  template <typename T, typename U>
  pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
    return make_pair(a.first - b.first, a.second - b.second);
  }
  template <typename T, typename U>
  pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
    return make_pair(a.first + b.first, a.second + b.second);
  }
  template <typename T, typename U>
  void umin(T& a, U b) {
    if (a > b) a = b;
  }
  template <typename T, typename U>
  void umax(T& a, U b) {
    if (a < b) a = b;
  }
  struct Sieve {
    struct PrimeIterator {
      int prime;
      int count;
      int num;
      const Sieve& sieve;
      PrimeIterator(int num, const Sieve& sieve) : num(num), sieve(sieve) {
        step();
      }
      void step() {
        void(0);
        prime = sieve.mn[num];
        count = 0;
        while (num != 1 && sieve.mn[num] == prime) {
          void(0);
          num /= sieve.mn[num];
          ++count;
        }
      }
      bool operator==(const PrimeIterator& other) const {
        return tie(prime, count, num) == tie(other.prime, other.count, other.num);
      }
      bool operator!=(const PrimeIterator& other) const {
        return !(*this == other);
      }
      PrimeIterator& operator++() {
        step();
        return *this;
      }
      pair<int, int> operator*() const { return {prime, count}; }
    };
    struct PrimeIteratorContainer {
      int num;
      const Sieve& sieve;
      PrimeIteratorContainer(int num, const Sieve& sieve)
          : num(num), sieve(sieve) {}
      PrimeIterator begin() const { return PrimeIterator(num, sieve); }
      PrimeIterator end() const { return PrimeIterator(1, sieve); }
    };
    vector<bool> isp;
    vector<int> primes;
    vector<int> mn;
    Sieve(int n, bool gen_primes = false, bool gen_mn = false) {
      isp.assign(n + 1, true);
      isp[0] = isp[1] = false;
      for (int i = 2; i * i <= n; ++i)
        if (isp[i])
          for (int j = i * i; j <= n; j += i) isp[j] = false;
      if (gen_primes)
        for (int i = 2; i <= n; ++i)
          if (isp[i]) primes.push_back(i);
      if (gen_mn) {
        mn.resize(n + 1);
        for (int i = 2; i <= n; ++i) {
          if (isp[i]) {
            mn[i] = i;
            if ((ll)i * i <= n)
              for (int j = i * i; j <= n; j += i) mn[j] = i;
          }
        }
      }
    }
    bool is_prime(int k) const { return isp[k]; }
    bool operator[](int k) const { return isp[k]; }
    PrimeIteratorContainer get_prime_divs(int k) const {
      return PrimeIteratorContainer(k, *this);
    }
    int phi(int n) const {
      auto v = get_prime_divs(n);
      for (auto [p, c] : v) n = n / p * (p - 1);
      return n;
    }
  };
  const int N = 1e6 + 10;
  int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    Sieve sieve(N, true, true);
    string s;
    cin >> s;
    vector<vector<pair<int, int>>> pos(N);
    vector<vector<int>> tor(N);
    for (int i = 0; i < n; ++i) {
      auto res = sieve.get_prime_divs(a[i]);
      int sign = (s[i] == '*' ? 1 : -1);
      for (auto [p, c] : res) {
        c *= sign;
        pos[p].emplace_back(i, c);
      }
    }
    vector<int> st;
    vector<int> good;
    for (int i = 0; i < pos.size(); ++i) {
      if (pos[i].empty()) continue;
      good.push_back(i);
      pos[i].insert(pos[i].begin(), make_pair(-1, 0));
      for (int j = 1; j < pos[i].size(); ++j)
        pos[i][j].second += pos[i][j - 1].second;
      tor[i].assign(pos[i].size(), pos[i].size());
      st.clear();
      for (int j = pos[i].size() - 1; j >= 0; --j) {
        while (!st.empty() && pos[i][st.back()].second >= pos[i][j].second)
          st.pop_back();
        if (!st.empty()) tor[i][j] = st.back();
        st.push_back(j);
      }
      pos[i].emplace_back(n, -1);
    }
    set<pair<int, int>> cur;
    for (int k : good) {
      cur.emplace(pos[k][tor[k][0]].first, k);
    }
    cur.emplace(n, 1e9);
    ll ans = 0;
    vector<int> ind(N, 0);
    for (int l = 0; l < n; ++l) {
      void(0);
      ans += cur.begin()->first - l;
      auto res = sieve.get_prime_divs(a[l]);
      for (auto [k, c] : res) {
        cur.erase({pos[k][tor[k][ind[k]]].first, k});
        ++ind[k];
        if (ind[k] < tor[k].size()) cur.insert({pos[k][tor[k][ind[k]]].first, k});
      }
    }
    cout << ans << '\n';
    return 0;
  }
  