-
Notifications
You must be signed in to change notification settings - Fork 0
/
Find Number
72 lines (62 loc) · 1.64 KB
/
Find Number
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* QUESTION STATEMENT Find Number
Given an integer N, You need to find the Nth smallest number which only contains odd digits i.e. 1,3,5,7,9
means no even digits are allowed on that number (12 will not consider). For example,
the starting numbers which only contain odd digits are 1,3,5,7,9,11,13,15,17,19,31,33,35 and so on.
*/
//{ Driver Code Starts
//Initial Template for Java
import java.util.*;
import java.io.*;
class GFG {
public static void main(String args[])throws IOException
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(System.out);
int t=Integer.parseInt(in.readLine());
while(t-->0){
long n=Long.parseLong(in.readLine());
Solution ob=new Solution();
out.println(ob.findNumber(n));
}
out.close();
}
}
// } Driver Code Ends
//User function Template for Java
class Solution
{
public long findNumber(long N)
{
long ans=0;
while(N!=0){
ans*=10;
if(N%5==0){
ans+=9;
N/=5;
N--;
}
else if(N%5==1){
ans+=1;
N/=5;
}
else if(N%5==2){
ans+=3;
N/=5;
}
else if(N%5==3){
ans+=5;
N/=5;
}
else{
ans+=7;
N/=5;
}
}
long temp = 0;
while(ans!=0){
temp = temp*10+ans%10;
ans/=10;
}
return temp;
}
}