forked from amankayat/HackerRank-Solution-Algorithm-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflipping_bits.cpp
More file actions
53 lines (47 loc) · 803 Bytes
/
flipping_bits.cpp
File metadata and controls
53 lines (47 loc) · 803 Bytes
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
#include<iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(){
int test;
cin>>test;
while(test>0){
int num;
cin>>num;
int k=0,p=0;
vector<pair<int,long long int> > a(33);
for(int i=0;i<=31;i++){
a[i].first = 1;
a[i].second =pow(2,i);
}
//display
long long int s=0;
for(int i=0;i<=31;i++){
cout<<a[i].first<<" "<<a[i].second<<"\n";
s+=a[i].second;
}
cout<<s;
// while(num>0){
// if(num%2!=0)
// {
// a[k].first = 0;
// k++;
// }else
// {
// a[k].first = 1;
// k++;
// }
// num=num/2;
// }
// for(int i=0;i<=31;i++)
// cout<<a[i].first<<" "<<a[i].second<<"\n";
// long long int sum=0;
// for(int i=0;i<=31;i++){
// if(a[i].first==1){
// sum+=a[i].second;
// }
// }
// cout<<sum<<endl;
test--;
}
}