题解 | #自守数#
自守数
https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e
#include <iostream> using namespace std; bool IsZiShouShu(int num) { int m = num*num; while (num != 0){ if (m % 10 != num % 10){ return false; } else{ m = m / 10; num = num / 10; } } return true; } int main() { int n, cnt = 0; cin >> n; for (int i = 0; i <= n; i++){ if (IsZiShouShu(i)){ cnt++; } } cout << cnt <<endl; }