티스토리 뷰
import java.io.*;
import java.util.StringTokenizer;
class Solution {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
int T = Integer.parseInt(br.readLine());
for (int t = 1; t <= T; t++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int s = Integer.parseInt(st.nextToken());
int e = Integer.parseInt(st.nextToken());
int cnt = 0;
for (int i = s; i <= e; i++) {
double sqrt = Math.sqrt(i);
if (sqrt % 1 != 0) {
continue;
}
if (isPalindrome(i) && isPalindrome((int) sqrt)) {
cnt++;
}
}
sb.append("#" + t + " " + cnt + "\n");
}
System.out.println(sb);
}
static boolean isPalindrome(int num) {
String str = String.valueOf(num);
int mid = str.length() / 2;
for (int i = 0; i < mid; i++) {
if (str.charAt(i) != str.charAt(str.length() - (i + 1))) {
return false;
}
}
return true;
}
}