题解 | #自守数#

自守数

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

#include <iostream>
#include <cmath>
using namespace std;

int main() {
    int n;
    int res = 0;
    cin >> n;

    for(int i=0; i<=n; i++){
        int a = pow(i,2), b = i;
        int num = 1;
        while(b/10 != 0){
            num += 1;
            b /= 10;
        }
        int s = pow(10,num);
        a %= s;
        if(a == i){
            res ++;
        }
    }
    cout << res << endl;
    return 0;
}
// 64 位输出请用 printf("%lld")

这个题的特点在于如何截取大数的低几位数据。

全部评论

相关推荐

11-23 15:14
中原工学院 Java
点赞 评论 收藏
分享
迷茫的大四🐶:你这个拿去投央国企吧,投私企包过不了的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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