Advertisement
pablosoares

1166

Sep 13th, 2020
901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. // over //
  5. using namespace std;
  6. int array[51];
  7. int total, N; //contador_steps=0;
  8.  
  9. void calcula(int v, int p){
  10.     //contador_steps++;
  11.     if(p == N) return;
  12.    
  13.     if(array[p] == 0){
  14.         array[p] = v;
  15.         total++;
  16.       //  contador_steps++;
  17.         return calcula(v+1, p);
  18.     }
  19.     for(int i = 0; i <= p; i++){
  20.         int raiz = (int) sqrt(array[i] + v);  // verifica se a soma das bolas formam um numero de quadrado perfeito//
  21.         if(pow(raiz,2) == array[i] + v){   
  22.             array[i] = v;
  23.             total++;
  24.            // contador_steps++;
  25.             return calcula(v+1, p);
  26.         }
  27.     }
  28.     calcula(v, p + 1);
  29. }
  30.  
  31. int main() {
  32.     int testes;
  33.     cin>> testes;
  34.     for (int i=0; i<testes; i++){
  35.         cin>> N;
  36.         for(int i=0; i<50; i++)
  37.             array[i]= 0;         //preenche o vetor 'array' com o valor 0//
  38.         total = 0;
  39.        // contador_steps=0;
  40.         calcula(1, 0);
  41.         cout << total <<endl;
  42.        // cout <<"Execucoes: "<< contador_steps<<endl;
  43.     }
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement