-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathDivisibility_by_2^n.cpp
More file actions
58 lines (57 loc) · 1.29 KB
/
Copy pathDivisibility_by_2^n.cpp
File metadata and controls
58 lines (57 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n ;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
int count2 = 0;
for(int i=0;i<n;i++){
while(arr[i]%2==0 && arr[i] > 1){
arr[i] = arr[i]/2;
count2++;
}
}
if(count2 >= n){
cout<<0<<endl;
}
else{
vector<int> v2;
int mul = 0;
int j =0;
for(int i=2;i<=n ;i++){
int ind = i;
int index2 = 0;
while(ind%2==0 && ind > 1){
ind = ind/2;
index2++;
mul++;
}
v2.push_back(index2);
}
if((mul+count2) >= n){
int ans =0;
sort(v2.begin() , v2.end());
reverse(v2.begin() , v2.end());
for(auto x: v2){
ans++;
count2+=x;
if(count2 >= n){
break;
}
}
cout<<ans<<endl;
}
else{
cout<<-1<<endl;
}
}
}
return 0;
}