Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. // TEMPLATE {{{
  6. #ifndef LOCAL
  7. #define OJ 1
  8. #else
  9. #define OJ 0
  10. #endif
  11.  
  12. #define endl '\n'
  13. #define TIMESTAMP merr << "Execution time: " << (double)clock()/CLOCKS_PER_SEC << " s.\n"
  14. class C_ {}; template <typename T> C_& operator <<(C_& __m, const T& __s) { if (!OJ) cerr << "\E[91m" << __s << "\E[0m"; return __m; }
  15. C_ merr;
  16.  
  17. struct __s { __s() { if (OJ) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s(){ TIMESTAMP; } } __S;
  18. /// END OF TEMPLATE }}}
  19.  
  20. int A[1000001];
  21.  
  22. int lp[1000001];
  23. void eratosphen() {
  24.   for (int i = 2; i < 1000001; i++) {
  25.     if (lp[i]) continue;
  26.     for (int j = i; j < 1000001; j+=i) {
  27.       if (lp[j]) continue;
  28.       lp[j] = i;
  29.     }
  30.   }
  31. }
  32.  
  33. int pp[11];
  34. int dd[11];
  35. int cnt;
  36. int xx;
  37. bool u[1000001];
  38. int ans;
  39.  
  40. inline void rec(int idx, int cur) {
  41.   if (idx == cnt) {
  42.     if (xx*1LL*xx > 1000000LL*cur) return;
  43.     long long a2 = xx*1LL*xx/cur;
  44.     if (a2 <= 1000000) {
  45.       ans += (u[cur] && u[a2]);
  46.     }
  47.     return;
  48.   }
  49.   for (int i = 0; i <= dd[idx]; i++) {
  50.     rec(idx+1, cur);
  51.     if (cur*1LL*pp[idx] >= xx) return;
  52.     cur *= pp[idx];
  53.   }
  54. }
  55.  
  56. inline void go(int x) {
  57.   int nn = x;
  58.   cnt = 0;
  59.   while (nn > 1) {
  60.     int p = lp[nn];
  61.     pp[cnt] = p;
  62.     dd[cnt] = 2;
  63.     nn /= p;
  64.     while (lp[nn] == p) {
  65.       dd[cnt] += 2;
  66.       nn /= p;
  67.     }
  68.     cnt++;
  69.   }
  70.   xx = x;
  71.   rec(0, 1);
  72. }
  73.  
  74. int main( void ) {
  75.   int n;
  76.   eratosphen();
  77.   cin >> n;
  78.   for (int i = 0; i < n; i++) {
  79.     cin >> A[i];
  80.     u[A[i]] = 1;
  81.   }
  82.   for (int i = 1; i < n-1; i++) {
  83.     int a = A[i];
  84.     go(a);
  85.   }
  86.   cout << ans << endl;
  87.   return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement