-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdualpal.java
More file actions
79 lines (71 loc) · 1.84 KB
/
Copy pathdualpal.java
File metadata and controls
79 lines (71 loc) · 1.84 KB
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
72
73
74
75
76
77
78
79
/*
ID: adimagg1
LANG: JAVA
TASK: dualpal
*/
import java.io.*;
import java.util.*;
class dualpal {
public static void main (String [] args) throws IOException {
// Use BufferedReader rather than RandomAccessFile; it's much faster
File f = new File("dualpal.in");
Scanner in = new Scanner(f);
// input file name goes above
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("dualpal.out")));
int indexer = 0;
int n = in.nextInt();
int s = in.nextInt();
long[] arr = new long[n];
for(long i = s+1; i<9920384;i++){
int count = 0;
for(int b = 2; b<11;b++){
if(isPal(convert(i,b))){
count++;
}
}
if(count>=2){
arr[indexer] = i;
indexer++;
}
if(indexer>=n){
break;
}
}
for(long h : arr){
out.print(h);
out.println();
}
out.close();
}
public static String convert(long inputNum, int base1){
String s = "";
// Convert input number is given
// base by repeatedly dividing it
// by base and taking remainder
while (inputNum > 0)
{
s += reVal(inputNum % base1);
inputNum /= base1;
}
StringBuilder ix = new StringBuilder();
// append a string into StringBuilder input1
ix.append(s);
// Reverse the result
return new String(ix.reverse());
}
public static char reVal(long num)
{
if (num >= 0 && num <= 9)
return (char)(num + 48);
else
return (char)(num - 10 + 65);
}
public static boolean isPal(String s){
for(int i = 0; i<= (s.length()/2); i++){
if(s.charAt(i) != s.charAt(s.length()-i-1)){
return false;
}
}
return true;
}
}