fork download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. double root(double x, double k)
  5. {
  6. double wynik;
  7. wynik=exp((log(x))/k);
  8. return wynik;
  9. }
  10. int main()
  11. {
  12. unsigned int t;
  13. cin >> t;
  14. while(t--)
  15. {
  16. int n;
  17. cin >> n;
  18. double *tab=new double[n];
  19. for(unsigned short i=0;i<n;i++)
  20. {
  21. cin >> tab[i];
  22. }
  23. unsigned int pot;
  24. double k=0.00, hist=-1.00;
  25. while(true)
  26. {
  27. double tmp, x;
  28. for(unsigned short i=0;i<n;i++)
  29. {
  30. tmp+=((pow(tab[i],k))/n);
  31. }
  32. x=root(tmp,k);
  33. if(x>=4.00){pot=k; break;}
  34. else if(x==hist){pot=(-1); break;}
  35. hist=x;
  36. k++;
  37. }
  38. cout << pot << "\n";
  39. delete [] tab;
  40. tab=0;
  41. }
  42. }
Success #stdin #stdout 0.02s 2860KB
stdin
4
5
1 2 3 1 3
4
1 2 3 5
5
1 1 5 1 1
2
4 2
stdout
647
0
0
0