Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- // TEMPLATE {{{
- #ifndef LOCAL
- #define OJ 1
- #else
- #define OJ 0
- #endif
- #define endl '\n'
- #define TIMESTAMP merr << "Execution time: " << (double)clock()/CLOCKS_PER_SEC << " s.\n"
- class C_ {}; template <typename T> C_& operator <<(C_& __m, const T& __s) { if (!OJ) cerr << "\E[91m" << __s << "\E[0m"; return __m; }
- C_ merr;
- struct __s { __s() { if (OJ) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s(){ TIMESTAMP; } } __S;
- /// END OF TEMPLATE }}}
- int A[1000001];
- int lp[1000001];
- void eratosphen() {
- for (int i = 2; i < 1000001; i++) {
- if (lp[i]) continue;
- for (int j = i; j < 1000001; j+=i) {
- if (lp[j]) continue;
- lp[j] = i;
- }
- }
- }
- int pp[11];
- int dd[11];
- int cnt;
- int xx;
- bool u[1000001];
- int ans;
- inline void rec(int idx, int cur) {
- if (idx == cnt) {
- if (xx*1LL*xx > 1000000LL*cur) return;
- long long a2 = xx*1LL*xx/cur;
- if (a2 <= 1000000) {
- ans += (u[cur] && u[a2]);
- }
- return;
- }
- for (int i = 0; i <= dd[idx]; i++) {
- rec(idx+1, cur);
- if (cur*1LL*pp[idx] >= xx) return;
- cur *= pp[idx];
- }
- }
- inline void go(int x) {
- int nn = x;
- cnt = 0;
- while (nn > 1) {
- int p = lp[nn];
- pp[cnt] = p;
- dd[cnt] = 2;
- nn /= p;
- while (lp[nn] == p) {
- dd[cnt] += 2;
- nn /= p;
- }
- cnt++;
- }
- xx = x;
- rec(0, 1);
- }
- int main( void ) {
- int n;
- eratosphen();
- cin >> n;
- for (int i = 0; i < n; i++) {
- cin >> A[i];
- u[A[i]] = 1;
- }
- for (int i = 1; i < n-1; i++) {
- int a = A[i];
- go(a);
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement