File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+ using namespace std ;
3+
4+ int lengthOfNumber (int k)
5+ {
6+ if (k%2 == 0 || k%5 == 0 ){
7+ return -1 ;
8+ }
9+ long long int n = 0 ;
10+ for (int i=1 ; i<=k; i++){
11+ int n = ((n*10 )+1 ) % k;
12+ if (n==0 ){
13+ return i;
14+ }
15+ }
16+ return -1 ;
17+ }
18+
19+ int main (){
20+
21+ int k = 1 ;
22+ cout << lengthOfNumber (k);
23+
24+ return 0 ;
25+ }
Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+ using namespace std ;
3+ int swapAdjacentBits (int n)
4+ {
5+ // Write your code here
6+ if (n == 0 ){
7+ return n;
8+ }
9+ vector<int > bitt;
10+ while (n!=0 ){
11+ bitt.push_back (n%2 );
12+ n/=2 ;
13+ }
14+ if (bitt.size ()%2 != 0 ){
15+ bitt.push_back (0 );
16+ }
17+ reverse (bitt.begin (), bitt.end ());
18+ int num = 0 ;
19+ int po = 0 ;
20+ for (int i=0 ; i<bitt.size ()-1 ; i++){
21+ swap (bitt[i], bitt[i+1 ]);
22+ i++;
23+ }
24+ for (int i=bitt.size ()-1 ; i>=0 ; i--){
25+ if (bitt[i] == 1 ){
26+ num += pow (2 , po);
27+ }
28+ po++;
29+ }
30+ return num;
31+ }
32+
33+ int main (){
34+
35+ int n = 9 ;
36+ cout << swapAdjacentBits (n) << endl;
37+
38+ return 0 ;
39+ }
You can’t perform that action at this time.
0 commit comments