fork(2) download
  1. /** Jai Shree Ram **/
  2. /** ssavi. ICT-4 CoU **/
  3.  
  4. #include<bits/stdc++.h>
  5. #define DIST(x1,x2, y1, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
  6. #define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
  7. #define CLR(a) a.clear()
  8. #define VCLR(a, n) for(int i=0; i<=n+3; i++) a[i].clear()
  9. #define SIZE(a) a.size()
  10. #define ERASE(a, b) memset(a, b, sizeof a)
  11. #define pb push_back
  12. #define LL long long
  13. #define ULL unsigned long long
  14. #define DBG cout<<"I Am Here"<<endl
  15. #define DBGA(a) cout<<a<<endl
  16. #define DBGI(b,a) cout<<b<<' '<<a<<endl
  17. #define DBGL(i,s,e,b) or(int i=s; i<=e; i++) cout<<b<<endl
  18. #define INF 1e9
  19. #define INV 1e-6
  20. #define sc(a) scanf("%I64d", &a)
  21. #define pr(a) printf("%I64d\n", a)
  22. #define si(a) scanf("%d", &a)
  23. #define pii pair<int,int>
  24. #define PII pair<LL,LL>
  25. #define MAX 600005
  26. #define CASE(i) printf("Case %d:", i);
  27. #define PI acos(-1)
  28. #define piis pair<int, string>
  29. #define fast1 ios_base::sync_with_stdio(false);
  30. #define fast2 cin.tie(0)
  31. #define CHECK_BIT(var,pos) ((var & (1 << pos)) == (1 << pos))
  32. #define LOOP(i, b, n) for(i=b; i<=n; i++)
  33. #define nl puts("")
  34.  
  35.  
  36. using namespace std;
  37.  
  38. /** ---------------------------------------------- **/
  39. /** Header And Defintions Ends Here. **/
  40. /** ---------------------------------------------- **/
  41.  
  42. const double GRS = (1 + sqrt(5))/2;
  43.  
  44. LL power(int X, int P)
  45. {
  46. LL ans = 1;
  47. for(int i=1; i<=P; i++){
  48. ans = ans * (LL)X;
  49. }
  50. return ans;
  51. }
  52.  
  53. LL ABS(LL A, LL B)
  54. {
  55. LL ret = A - B;
  56. if(ret<0) return -ret;
  57. return ret;
  58. }
  59.  
  60. LL MOD = 1000000007;
  61. const LL BIGMAX = power(2,63) - 1;
  62.  
  63. LL ADD(LL X, LL Y)
  64. {
  65. if(X+Y<0)
  66. return (X - MOD) + Y;
  67. else if(X+Y>=MOD)
  68. return X+Y-MOD;
  69. else
  70. return X+Y;
  71. }
  72.  
  73. LL prod(LL X, LL Y) // CUSTOM PRODUCT FUNCTION FOR BIG NUMBER MULTIPLICATION
  74. {
  75. if(Y==0 || X<=(BIGMAX/Y)) return (X*Y)%MOD;
  76. LL result = 0;
  77.  
  78. if(X>Y) swap(X,Y);
  79. while(X>0){
  80. if(X&1!=0){
  81. result = ADD(result, Y);
  82. }
  83. X>>=1;
  84. Y -= MOD - Y;
  85. if(Y<0)
  86. Y = Y + MOD;
  87. }
  88. return result;
  89. }
  90.  
  91. LL bigmod(LL a, LL b){
  92. LL x = 1, y = a%MOD;
  93. while(b > 0) {
  94. if(b%2 == 1) {
  95. x = prod(x,y);
  96. }
  97. y = prod(y,y);
  98. b /= (LL)2;
  99. }
  100. return x;
  101. }
  102.  
  103. LL MODINVERSE(LL a){
  104. return bigmod(a, MOD-2);
  105. }
  106.  
  107. LL ncrdp[900][1000];
  108. LL NCR(int n, int r)
  109. {
  110. if(r==1) return n;
  111. else if(n==r) return 1;
  112. else
  113. {
  114. if(ncrdp[n][r]!=-1) return ncrdp[n][r];
  115. else
  116. {
  117. ncrdp[n][r]=NCR(n-1,r) + NCR(n-1,r-1);
  118. return ncrdp[n][r];
  119. }
  120. }
  121. }
  122.  
  123. const int MAXN = 1000005;
  124. int status[(MAXN/32)+10];
  125. vector<int>primelist;
  126.  
  127. bool check(int n, int pos) { return (bool)(n & (1<<pos)); }
  128. int SET(int n, int pos){ return n=n|(1<<pos);}
  129.  
  130. void sieve()
  131. {
  132. int sqrtN=int (sqrt(MAXN));
  133. status[1>>5]=SET(status[1>>5],1&31);
  134. for(int j=4; j<=MAXN; j=j+2)
  135. status[j>>5]=SET(status[j>>5],j&31);
  136. for(int i=3; i<=sqrtN; i=i+2)
  137. {
  138. if(check(status[i>>5],i&31)==0)
  139. {
  140. for(int j=i*i; j<=MAXN; j= j + (i<<1))
  141. {
  142. status[j>>5]=SET(status[j>>5],j&31);
  143. }
  144. }
  145. }
  146. primelist.push_back(2);
  147. for(int i=3; i<=MAXN; i=i+2)
  148. {
  149. if(check(status[i>>5],i&31)==0) {
  150. primelist.push_back(i);
  151. }
  152. }
  153. }
  154.  
  155.  
  156. /**----------------------------------------------------------------------------**/
  157. /** Template Ends Here. Main Function And User Defined Functions Starts Here. **/
  158. /**--------------------------------------------------------------------------**/
  159.  
  160. int cnt[1005];
  161. int arr[1005];
  162.  
  163. int main()
  164. {
  165. int test, caseno;
  166. scanf("%d", &test);
  167. LOOP(caseno, 1, test)
  168. {
  169. memset(cnt, 0, sizeof cnt);
  170. int n, x, m = 1;
  171. scanf("%d", &n);
  172. for(int i=1; i<=n; i++){
  173. scanf("%d", &x);
  174. if(cnt[x]==0){
  175. arr[m++] = x;
  176. }
  177. cnt[x]++;
  178. }
  179.  
  180. int tot = 0;
  181. for(int i=1; i<m; i++)
  182. {
  183. for(int j=i; j<m; j++)
  184. {
  185. int dr = tot;
  186. if(i==j){
  187. if(cnt[arr[i]]>1){
  188. int a = arr[i] + arr[j];
  189. if(cnt[a]>0){
  190. if(a==arr[i] && a==arr[j]){
  191. if(cnt[a]>2) tot++;
  192. }
  193. else if(a==arr[i]){
  194. if(cnt[a]>1) tot++;
  195. }
  196. else if(a==arr[j]){
  197. if(cnt[a]>1) tot++;
  198. }
  199. else{
  200. tot++;
  201. }
  202. // if(tot!=dr)
  203. // cout<<arr[i]<<' '<<arr[j]<<' '<<a<<endl;
  204. }
  205. }
  206. }
  207. else{
  208. int a = arr[i] + arr[j];
  209. if(cnt[a]>0){
  210. if(a==arr[i] && a==arr[j]){
  211. if(cnt[a]>2) tot++;
  212. }
  213. else if(a==arr[i]){
  214. if(cnt[a]>1) tot++;
  215. }
  216. else if(a==arr[j]){
  217. if(cnt[a]>1) tot++;
  218. }
  219. else{
  220. tot++;
  221. }
  222. // if(tot!=dr)
  223. // cout<<arr[i]<<' '<<arr[j]<<' '<<a<<endl;
  224. }
  225. }
  226. }
  227. }
  228. CASE(caseno);
  229. printf(" %d\n", tot);
  230.  
  231. }
  232. }
  233.  
Success #stdin #stdout 0s 10640KB
stdin
10
5
2 4 6 8 10
4
5 2 3 7
9
1 3 3 5 2 4 6 6 6
10
1 3 3 3 5 2 4 6 6 6
5
0 1 1 2 0
6
0 0 1 1 2 0
5
1 1 2 2 3
6
1 1 2 2 3 4
5
0 0 0 0 0
6
0 1 0 1 0 2
stdout
Case 1: 4
Case 2: 2
Case 3: 7
Case 4: 7
Case 5: 2
Case 6: 3
Case 7: 2
Case 8: 4
Case 9: 1
Case 10: 3