题解 | #自守数#
自守数
http://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s=null;
while((s=br.readLine())!=null){
//char[] chars=s.toCharArray();
int n=Integer.valueOf(s);
int count=0;
for(int i=0;i<=n;i++){
if(isZishoushu(i)!=-1){
count++;
}
}
System.out.println(count);
}
}
public static int isZishoushu(int b){
int n=b;
int power=n*n;
int counts=0;
while(n>0){
n=n/10;
counts++;
}
int flag=0;
for(int i=0;i<counts;i++){
if(power%10!=b%10){
return -1;
}
b=b/10;
power=power/10;
}
return n;
}
}