fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main(){
  4. int t;cin>> t;
  5. while (t--){
  6. int n ;cin>>n;
  7. int con =0;
  8. long long a[n];
  9. for(int i=0;i<n;i++){
  10. cin>>a[i];
  11. }
  12. for (int i=0;i<n;i++){
  13. while (a[i]%2==0){
  14. a[i]/=2;
  15. con++;
  16. }
  17. }
  18. if (con>=n){
  19. cout << '0' << '\n';
  20. continue;
  21. }
  22. int need;
  23. need =n-con;
  24. int z=1;
  25. int con2=0;
  26. while (need >0){
  27. z*=2;
  28. need--;
  29. }
  30.  
  31. for (int i=0;i<n;i++){
  32. while (a[i]%2==0){
  33. con2++;
  34. }
  35. }
  36. long long mx[con2];
  37. for (int j=0;j<n;j++){
  38. if (a[j]%2==0){
  39. mx[j] =a[j];
  40. }
  41. }
  42. sort (mx,mx+con2);
  43. reverse (mx,mx+con2);
  44. int res=0;
  45. int conmx;
  46. for (int j=0;j<con2;j++)
  47. {
  48. int c=z/mx[j];
  49. while (mx[j]%2==0){
  50. mx[j]/=2;
  51. conmx++;
  52. }
  53. res+=conmx*c;
  54. conmx=0;
  55. if (z==0){
  56. cout << res << '\n';
  57. }
  58. else if (j==con2 && res>0){
  59. cout << "-" << '1' << '\n';
  60. }
  61. }
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. }
  80. }
  81.  
Success #stdin #stdout 0s 5348KB
stdin
Standard input is empty
stdout
0
0