题解 | #自守数#
自守数
https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); int count=0; for(int i=0;i<=num;i++){ if(isNum(i)) count++; } System.out.println(count); } public static boolean isNum(int i){ int mul = i*i; while(i!=0){ //从后向前比较i和mul,如果是自守数,应该是相同的 if(i%10==mul%10){ i = i/10; mul = mul/10; }else{ return false; } } return true; } }