forked from matthewsamuel95/ACM-ICPC-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed infinite loop from Nth magic no.
- Loading branch information
Showing
1 changed file
with
14 additions
and
10 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 |
---|---|---|
@@ -1,25 +1,29 @@ | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
int nthMagicNo(int n) | ||
{ | ||
int pow = 1, answer = 0; | ||
|
||
|
||
|
||
while (n) | ||
{ | ||
pow = pow*5; | ||
|
||
if (n & 1) | ||
answer += pow; | ||
|
||
pow = pow*5; | ||
|
||
|
||
if (n & 1) | ||
answer += pow; | ||
|
||
|
||
n >>= 1; | ||
} | ||
return answer; | ||
} | ||
|
||
int main() | ||
{ | ||
int n; | ||
cin>>n; | ||
cin>>n; | ||
cout << "nth magic number is " << nthMagicNo(n) << endl; | ||
return 0; | ||
} | ||
} |