题解 | #自守数#
自守数
https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
import java.util.*; public class Main { public static void main(String[] args) { Scanner fzhinput = new Scanner(System.in); int sz = fzhinput.nextInt(); int num = 0, dbz = 0; for (int i = 0; i <= sz; i++) { int z = i * i; if (i < 10) { dbz = z % 10; } else if (i < 100) { dbz = z % 100; } else if (i < 1000) { dbz = z % 1000; } else if (i < 10000) { dbz = z % 10000; } else if (i < 100000) { dbz = z % 100000; } if (i == dbz) { num++; } else { } } System.out.println(num); } }