Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using ll = long long;
- constexpr int mod = 1e9 + 7;
- class Solution {
- public:
- int subsequencePairCount(vector<int>& ns) {
- int n = ns.size();
- using a3i = array<int, 3>;
- // map<a3i, ll> cache;
- // vector<vector<vector<int>>> cache(201, vector<vector<int>>(201, vector<int>(201, -1)));
- // map<int, map<int, map<int, int>>> cache;
- using a2i = array<int, 2>;
- vector<map<a2i, int>> cache(201);
- function<int(int, int, int)> get = [&](int i, int j, int k) {
- if (i < 0) return int(j == k);
- // if (cache[i][j][k] != -1) return cache[i][j][k];
- // if (cache.count(i) && cache[i].count(j) && cache[i][j].count(k)) return cache[i][j][k];
- if (cache[i].count({j, k})) return cache[i][{j, k}];
- int v = ns[i];
- //return cache[i][j][k] = (get(i-1, j, k) + get(i-1, gcd(j, v), k) + get(i-1, j, gcd(k, v))) % mod;
- return cache[i][{j,k}] = (ll(get(i-1, j, k)) + ll(get(i-1, gcd(j, v), k)) + ll(get(i-1, j, gcd(k, v)))) % mod;
- };
- return (get(n-1, 0, 0) + mod - 1) % mod;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement