Tarango

Untitled

Oct 30th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <string>
  6. #include <math.h>
  7. #include <string.h>
  8. #include <map>
  9. #include <set>
  10. #include <utility>
  11. #include <stack>
  12. #include <queue>
  13. #include <vector>
  14. using namespace std;
  15.  
  16. const int len = 300000 + 9 ;
  17.  
  18. int nCase,n,lim,ans,temp,data[len];
  19.  
  20.  
  21. void pair_Search(int val,int st,int en){
  22.     //cout << val << endl;
  23.     if(st<=en){
  24.         int sum=data[st]+data[en];
  25.         if(sum==val){
  26.             temp++;
  27.             pair_Search(val,st+1,en-1);
  28.         }else if(val<sum){
  29.             pair_Search(val,st,en-1);
  30.         }else{
  31.             pair_Search(val,st+1,en);
  32.         }
  33.     }
  34.     return;
  35. }
  36.  
  37.  
  38. int main(){
  39.     for(int i=1;i<=300006;i++){
  40.         data[i]=i;
  41.     }
  42.     scanf("%d",&nCase);
  43.     while(nCase--){
  44.         ans=0;
  45.         scanf("%d",&n);
  46.         lim=n/2;
  47.         while(true){
  48.             temp=0;
  49.             pair_Search(n-lim,1,lim);
  50.             ans+=temp;
  51.             if(temp==0){
  52.                 break;
  53.             }
  54.             lim--;
  55.         }
  56.         printf("%d\n",ans);
  57.  
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment