题解 | #自守数#

自守数

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

#include <iostream>
using namespace std;

bool isO(int x) {
    int x2 = x * x;
    int x3 = x2 - x;
    bool res = false;
    if (x < 10) {
        if (x3 % 10 == 0) {
            res = true;
        }
    } else if (x >= 10 && x < 100) {
        if (x3 % 100 == 0) {
            res = true;
        }

    } else if (x >= 100 && x < 1000) {
        if (x3 % 1000 == 0) {
            res = true;
        }

    } else if (x >= 1000 && x < 10000) {
        if (x3 % 10000 == 0) {
            res = true;
        }
    }
    return res;

}

int main() {
    int n;
    cin >> n;
    int cnt = 1;
    for (int i = 1; i <= n ; i++) {
        if (isO(i)) {
            cnt++;
        }
    }
    cout << cnt;
}

取余计算

全部评论

相关推荐

这不纯纯作弊了吗😢😢😢
编程界菜鸡:信这个的这辈子有了,这智商你靠啥都没用
点赞 评论 收藏
分享
人力小鱼姐:实习经历没有什么含金量,咖啡店员迎宾这种就别写了,其他两段包装一下 想找人力相关的话,总结一下个人优势,结合校园经历里有相关性的部分,加一段自我评价
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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