题解 | #Digital Roots# 数论做法

Digital Roots

https://www.nowcoder.com/practice/cef727d0af33479c9fb4a9c120702414

#include <iostream>
using namespace std;

int main() {
    int a;
    while (cin >> a) {
        if (a % 9 == 0) {
            cout << 9 << endl;
        } else {
            cout << a % 9 << endl;
        }
    }
}

易知结果和最初的数字除以9同余,且当数字是9的倍数时,结果为9(不是0)

有兴趣的可以自己证明一下

全部评论

相关推荐

一天代码十万三:实习东西太少了,而且体现不出你业务,3个月不可能就这点产出吧,建议实习多写点,玩具项目面试官都不感兴趣的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务