#include <stdio.h> #include <math.h>

// 判断一个数是否是自守数 int isAutomorphic(int num) { int square = num * num; while (num > 0) { if (num % 10 != square % 10) { return 0; } num /= 10; square /= 10; } return 1; }

// 找到指定位数的自守数 void findAutomorphic(int n) { int start = pow(10, n-1); int end = pow(10, n);

for (int i = start; i < end; i++) {
    if (isAutomorphic(i)) {
        printf('%d\n', i);
    }
}

}

int main() { int n; scanf('%d', &n);

findAutomorphic(n);

return 0;

}

自守数生成器:C语言代码实现 (n 位自守数)

原文地址: https://www.cveoy.top/t/topic/crK7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录