We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7087bdf commit fbee54aCopy full SHA for fbee54a
BitManipulation/Nth_magic_number/nth_magic_number.cpp
@@ -1,25 +1,29 @@
1
#include <bits/stdc++.h>
2
using namespace std;
3
-
+
4
int nthMagicNo(int n)
5
{
6
int pow = 1, answer = 0;
7
8
9
while (n)
10
- pow = pow*5;
11
12
- if (n & 1)
13
- answer += pow;
14
+ pow = pow*5;
+ if (n & 1)
15
+ answer += pow;
16
17
18
+ n >>= 1;
19
}
20
return answer;
21
22
23
int main()
24
25
int n;
- cin>>n;
26
+ cin>>n;
27
cout << "nth magic number is " << nthMagicNo(n) << endl;
28
return 0;
-}
29
+}
0 commit comments