题解 | #自守数#
自守数
https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
#include <math.h>
#include <stdio.h>
#include <string.h>
int judg(int n){
char str[100001];
sprintf(str, "%d", n);
int len = strlen(str);
int squ = pow(n, 2);
int tmp = squ % (int)pow(10, len);
if(tmp == n)
return 1;
else
return 0;
}
int main(){
int n;
scanf("%d", &n);
int count = 0;
for(int i = 0; i <= n; i++){
while(judg(i)){
count++;
break;
}
}
printf("%d", count);
return 0;
}


查看14道真题和解析