用C寫了一個
語法:
#include<stdio.h>
#define snum_MAX 17
void translate(int N, long decimal_num, char *result_num, int *result_digit);
int Is_symmetry(char data[], int digit);
void print_result(int num, char data[], int digit);
void main(){
int i, B, digit;
char snum[snum_MAX];
long num;
scanf("%d", &B);
for(i = 1;i <= 300;i++){
num = (long)i * (long)i;
translate(B, num, snum, &digit);
if(Is_symmetry(snum, digit))
print_result(i, snum, digit);
}
}
void translate(int N, long decimal_num, char *result_num, int *result_digit){
*result_digit = 0;
while(decimal_num){
*result_num = decimal_num % N;
result_num++;
decimal_num /= N;
(*result_digit)++;
}
*result_num = '\0';
}
int Is_symmetry(char data[], int digit){
int i, j;
i = 0;
j = digit - 1;
while(data[i] == data[j] && i <= j){
i++;
j--;
}
return (i > j);
}
void print_result(int num, char data[], int digit){
while(digit){
digit--;
if(data[digit] < 10) data[digit] += 0x30;
else data[digit] += 0x37;
}
printf("%d\t%s\n", num, data);
}