Advertisement
Guest User

Untitled

a guest
Mar 16th, 2017
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.94 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define inf (1<<30)-1
  5. #define INF (1LL<<62)-1
  6. #define MOD 1000000007LL
  7. #define MP make_pair
  8. #define PB push_back
  9. #define ALL(x) x.begin(),x.end()
  10. #define PI acos(-1)
  11. #define MEM(x,y) memset(x,y,sizeof (x))
  12. #define debug cout<<"A"<<'\n'
  13. #define REP(i,a,b) for (int i=(a); i<=(b); i++)
  14. #define PER(i,a,b) for (int i=(a); i>=(b); i--)
  15. #define REPL(i,a,b) for (LL i=(a); i<=(b); i++)
  16. #define PERL(i,a,b) for (LL i=(a); i>=(b); i--)
  17. #define print(x) cout<<x<<'\n'
  18. #define dprint(a,x) cout<<setprecision(x)<<fixed<<a<<'\n'
  19. #define itrALL(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
  20. typedef long long LL;
  21. typedef unsigned long long ULL;
  22. typedef long double LD;
  23. typedef pair<int,int>PII;
  24. typedef pair<LL,LL>PLL;
  25. typedef set<int> SI;
  26. typedef set<LL> SL;
  27. typedef set<string> SS;
  28. typedef vector<int> VI;
  29. typedef vector<LL> VL;
  30. typedef vector<string> VS;
  31. typedef map<int,int> MII;
  32. typedef map<LL,LL> MLL;
  33. typedef queue<int> QI;
  34.  
  35. /* Direction Array */
  36.  
  37. // int fx[]={1,-1,0,0};
  38. // int fy[]={0,0,1,-1};
  39. // int fx[]={0,0,1,-1,-1,1,-1,1};
  40. // int fy[]={-1,1,0,0,1,1,-1,-1};
  41.  
  42. template <class T> inline T bigmod(T p,T e,T M)
  43. {
  44.     T ret = 1;
  45.     for(; e > 0; e >>= 1)
  46.     {
  47.         if(e & 1) ret = (ret * p) % M;
  48.         p = (p * p) % M;
  49.     } return (T)ret;
  50. }
  51.  
  52. template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
  53. template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}
  54. template <class T> inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/gcd(a,b))*b;}
  55. template <class T, class X> inline bool getbit(T a, X i) { T t=1; return ((a&(t<<i))>0);}
  56. template <class T, class X> inline T setbit(T a, X i) { T t=1;return (a|(t<<i)); }
  57. template <class T, class X> inline T resetbit(T a, X i) { T t=1;return (a&(~(t<<i)));}
  58.  
  59. inline LL power(LL a, LL b)
  60. {
  61.     LL multiply=1;
  62.     REP(i,1,b)
  63.     {
  64.         multiply*=a;
  65.     }
  66.     return multiply;
  67. }
  68. inline LL ABS(LL a){return (a>=0)?a:-a;}
  69.  
  70. /*end of header*/
  71. int n,arr[104];
  72. LL ans;
  73. unordered_map<int,int>mp;
  74. int main()
  75. {
  76.     //freopen("input_file_name.in","r",stdin);
  77.     //freopen("output_file_name.out","w",stdout);
  78.     scanf("%d",&n);
  79.     REP(i,1,n)scanf("%d",&arr[i]);
  80.     REP(i,1,n)
  81.     {
  82.         REP(j,i,n)
  83.         {
  84.             REP(k,1,n)
  85.             {
  86.                 if(mp.find(arr[i]*arr[j]+arr[k])==mp.end())mp[arr[i]*arr[j]+arr[k]]=0;
  87.                 if(i==j)mp[arr[i]*arr[j]+arr[k]]++;
  88.                 else mp[arr[i]*arr[j]+arr[k]]+=2;
  89.             }
  90.         }
  91.     }
  92.     ans=0;
  93.     REP(i,1,n)
  94.     {
  95.         if(arr[i]==0)continue;
  96.         REP(j,1,n)
  97.         {
  98.             REP(k,j,n)
  99.             {
  100.                 if(mp.find(arr[i]*(arr[j]+arr[k]))==mp.end())continue;
  101.                 if(j==k)ans+=mp[arr[i]*(arr[j]+arr[k])];
  102.                 else ans+=2LL*mp[arr[i]*(arr[j]+arr[k])];
  103.             }
  104.         }
  105.     }
  106.     printf("%lld\n",ans);
  107.     return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement