fork(1) download
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. int t, k, n;
  5. long long suma;
  6. double srednia;
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. cin>>t;
  13. while(t--)
  14. {
  15. cin>>n;
  16. int a[n];
  17. long long int iloczyn[n];
  18. for (int i=0; i<n; i++)
  19. {
  20. cin>>a[i];
  21. iloczyn[i]=1;
  22. }
  23. k=0;
  24. srednia=0;
  25. while (srednia<4)
  26. {
  27. k++;
  28. suma=0;
  29. for (int i=0; i<n; i++)
  30. {
  31. iloczyn[i]*=a[i];
  32. suma+=iloczyn[i];
  33. }
  34. srednia=pow(suma/n, 1.0/k);
  35. if (k==32) {k=-1; break;}
  36. }
  37. cout<<k<<endl;
  38. }
  39. return 0;
  40. }
Success #stdin #stdout 0.01s 5516KB
stdin
4
5
1 2 3 1 3
4
1 2 3 5
5
1 1 5 1 1
2
4 2
stdout
-1
6
8
-1