Advertisement
pablosoares

1166

Sep 13th, 2020
1,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int array[51];
  5. int total, N;
  6.  
  7. void calcula(int v, int p){
  8.    
  9.     int i;
  10.    
  11.      if(p == N) return;
  12.  
  13.     if(array[p] == 0){
  14.          array[p] = v;
  15.          total++;
  16.          return calcula(v+1, p);
  17.      }
  18.      for(i=0;i<=p;i++){
  19.          int raiz=(int)sqrt(array[i]+v);
  20.          if(pow(raiz,2)==array[i] + v){
  21.              array[i]=v;
  22.              total++;
  23.              return calcula(v+1,p);
  24.          }
  25.      }
  26.      calcula(v, p + 1);
  27.  }
  28.  
  29. int main() {
  30.      int testes,i,j;
  31.      scanf("%d",&testes);
  32.      for (i=0; i<testes; i++){
  33.          scanf("%d",&N);
  34.          for(j=0; j<50; j++)
  35.              array[j]= 0;
  36.          total = 0;
  37.          calcula(1, 0);
  38.          printf("%d\n",total);
  39.      }
  40.      return 0;
  41.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement