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;
  template <class T>
  bool chmax(T &a, const T &b) {
    if (a < b) {
      a = b;
      return 1;
    }
    return 0;
  }
  template <class T>
  bool chmin(T &a, const T &b) {
    if (a > b) {
      a = b;
      return 1;
    }
    return 0;
  }
  int N;
  int A[1010101];
  vector<int> V[1010101];
  string S;
  const int prime_max = 1000;
  vector<int> prime;
  int NP, divp[prime_max];
  void cprime() {
    if (NP) return;
    for (int i = 2; i < prime_max; i++)
      if (divp[i] == 0) {
        prime.push_back(i);
        NP++;
        for (signed long long j = 1LL * i * i; j >= i && j < prime_max; j += i)
          if (divp[j] == 0) divp[j] = i;
      }
  }
  int R[1010101];
  template <class V, int NV>
  class SegTree_2 {
   public:
    V nolink;
    vector<V> val;
    SegTree_2() {
      val.resize(NV * 2);
      clear();
      nolink = 1 << 30;
    };
    void clear() {
      for (int i = 0; i < NV * 2; i++) val[i] = 1 << 20;
    }
    V getval(int k) {
      int e = k + NV;
      V ret = nolink;
      while (e >= 1) ret = min(ret, val[e]), e /= 2;
      return ret;
    }
    void update(int x, int y, V v, int l = 0, int r = NV, int k = 1) {
      if (l >= r) return;
      if (x <= l && r <= y)
        val[k] = min(val[k], v);
      else if (l < y && x < r) {
        update(x, y, v, l, (l + r) / 2, k * 2);
        update(x, y, v, (l + r) / 2, r, k * 2 + 1);
      }
    }
  };
  SegTree_2<int, 1 << 20> st;
  void solve() {
    int i, j, k, l, r, x, y;
    string s;
    cprime();
    cin >> N;
    for (i = 0; i < (N); i++) {
      cin >> x;
      for (auto &p : prime)
        while (x % p == 0) {
          V[p].push_back(i);
          x /= p;
        }
      if (x > 1) V[x].push_back(i);
    }
    st.update(0, N, N - 1);
    cin >> S;
    for (i = 0; i < (1010000); i++)
      if (V[i].size()) {
        vector<int> A;
        for (auto &v : V[i]) {
          if (S[v] == '*') {
            A.push_back(v);
          } else {
            if (A.size()) {
              x = A.back();
              A.pop_back();
            } else {
              x = -1;
            }
            st.update(x + 1, v + 1, v - 1);
          }
        }
      }
    signed long long ret = 0;
    for (i = 0; i < (N); i++) {
      x = st.getval(i);
      ret += (x + 1) - i;
    }
    cout << ret << endl;
  }
  int main(int argc, char **argv) {
    string s;
    int i;
    if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
    for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
    for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
    cout.tie(0);
    solve();
    return 0;
  }
  