题解 | #大整数的因子#

大整数的因子

https://www.nowcoder.com/practice/3d6cee12fbf54ea99bb165cbaba5823d

//字符串除法模拟
#include <iostream>
#include <string>
using namespace std;

bool canModk(string s, int k){
    int current = 0;
    for(string::size_type i = 0; i < s.size(); i++){
        current = current * 10 + s[i] - '0';
        if(current >= k){
            s[i] = current / k + '0';
            current %= k;
        }
        else s[i] = '0';
    }
    if(current == 0) return true;
    else return false;
}

int main() {
    string s;
    while(getline(cin ,s)){
        if(s == "-1") break;
        else{
            bool first = true;
            for(int k = 2; k <= 9; k++){
                if(canModk(s, k)){
                    if(first) cout << k;
                    else cout << ' ' << k;
                    first = false;
                }
            }
            if(first) cout << "none";
            cout << endl;
        }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

一表renzha:手写数字识别就是一个作业而已
点赞 评论 收藏
分享
程序员小白条:你是沟通了900个,不是投了900份简历,你能投900份,意味着对面都要回复你900次,你早就找到实习了,没亮点就是这样的,别局限地区,时间投的也要早,现在都要7月了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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