-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3385 from animagus12/add-the-bit-game
Added the bit game
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// { Driver Code Starts | ||
#include <bits.h/stdc++.h> | ||
#include<iostream> | ||
using namespace std; | ||
// } Driver Code Ends | ||
|
||
class Solution | ||
{ | ||
public: | ||
int swapBitGame(long long N) | ||
{ | ||
// Code here | ||
int count = 0; | ||
while (N > 0) | ||
{ | ||
if (N % 2 == 1) | ||
{ | ||
count++; | ||
} | ||
N /= 2; | ||
} | ||
return (count % 2 == 0) ? 2 : 1; | ||
} | ||
}; | ||
|
||
// { Driver Code Starts | ||
int main() | ||
{ | ||
int t; | ||
cin >> t; | ||
while (t--) | ||
{ | ||
long long N; | ||
cin >> N; | ||
Solution ob; | ||
cout << ob.swapBitGame(N) << endl; | ||
} | ||
return 0; | ||
} | ||
// } Driver Code Ends |