题解 | #自守数#

自守数

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")

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

全部评论

相关推荐

07-07 14:30
复旦大学 Java
遇到这种人我也不知道说啥了
无能的丈夫:但我觉得这个hr语气没什么问题啊(没有恶意
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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