题解 | #自守数#

自守数

https://www.nowcoder.com/practice/88ddd31618f04514ae3a689e83f3ab8e

#include <stdio.h>

int main() {
    int n;
    while (scanf("%d", &n) != EOF) {
        int count = 0;
        for(int i = 0; i <= n; i++) {
            int square = i * i;
            int tempi = i;
            while(tempi != 0) {
                if(tempi % 10 == square % 10) {
                    tempi /= 10;
                    square /= 10;
                } else break;
            }
            if(tempi == 0) count++;
        }
        printf("%d\n", count);
    }
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务