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;
  int n;
  string s;
  int a[1000001];
  int b[1000001];
  int p[1000001];
  int f[1000001];
  vector<pair<int, int>> pos[1000001];
  class segment_tree {
   public:
    using pointer = segment_tree*;
    pointer left, right;
    int l, r, m;
    int val;
    segment_tree(int l, int r)
        : l(l), r(r), m((l + r) / 2), val(n), left(nullptr), right(nullptr) {
      if (l != r) {
        left = new segment_tree(l, m);
        right = new segment_tree(m + 1, r);
      }
    }
    void update(int u, int v, int a) {
      if (l > v || r < u) return;
      if (u <= l && v >= r)
        val = min(val, a);
      else {
        left->update(u, v, a);
        right->update(u, v, a);
      }
    }
    void get(int best = n) {
      best = min(best, val);
      if (l == r)
        f[l] = best;
      else {
        left->get(best);
        right->get(best);
      }
    }
  };
  segment_tree* tree;
  void add_query(int x, int y, int p) { tree->update(x, y, p); }
  void make(vector<pair<int, int>>& pos) {
    for (int i = 1; i < pos.size(); i++) pos[i].second += pos[i - 1].second;
    stack<int> temp;
    for (int i = ((int)pos.size()) - 1; i >= 0; i--) {
      while ((!temp.empty()) && (pos[i].second <= pos[temp.top()].second))
        temp.pop();
      int best = temp.empty() ? (n + 1) : pos[temp.top()].first;
      if (i + 1 >= pos.size())
        add_query(pos[i].first + 1, n, best - 1);
      else
        add_query(pos[i].first + 1, pos[i + 1].first, best - 1);
      temp.push(i);
    }
    while ((!temp.empty()) && (0 <= pos[temp.top()].second)) temp.pop();
    int best = temp.empty() ? (n + 1) : pos[temp.top()].first;
    add_query(1, pos[0].first, best - 1);
  }
  void solve() {
    for (int i = 2; i <= 1000000; i++)
      if (p[i] == 0)
        for (int j = i; j <= 1000000; j += i)
          if (p[j] == 0) p[j] = i;
    cin >> n;
    tree = new segment_tree(1, n);
    for (int i = 1; i <= n; i++) cin >> a[i];
    cin >> s;
    for (int i = 1; i <= n; i++)
      if (s[i - 1] == '*')
        b[i] = 1;
      else
        b[i] = -1;
    for (int i = 1; i <= n; i++) {
      int x = a[i];
      while (x > 1) {
        int k = p[x];
        pos[k].emplace_back(i, 0);
        while (x % k == 0) {
          pos[k].back().second += b[i];
          x /= k;
        }
      }
    }
    for (int i = 1; i <= 1000000; i++)
      if (!pos[i].empty()) {
        make(pos[i]);
      }
    tree->get();
    int64_t ans = 0;
    for (int i = 1; i <= n; i++) ans += (f[i] - i + 1);
    cout << ans << '\n';
  }
  int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    while (t--) {
      solve();
    }
  }
  