Java
注意输出对于大小写有要求,需要全大写
例如 16 进制下的 10 应表示为 A 而不是 a
import java.util.Scanner;
class Main{
static int b = 2;
public static void main(String[] args){
Scanner s = new Scanner(System.in);
b = s.nextInt();
for(int i = 1; i <= 300; i ++){
String chi = Integer.toString(i*i, b);
if(check(chi)){
System.out.println(Integer.toString(i, b).toUpperCase() + " " + chi.toUpperCase());
}
}
}
public static boolean check(String chi){
int num = chi.length();
for(int i = 0; i < num / 2; i ++){
if(chi.charAt(i) != chi.charAt(num - 1 -i)){
return false;
}
}
return true;
}
}