北京大学机试 大整数的因子 Easy

基本思想:

无;

关键点:

无;

#include<iostream>
#include<string>
#include<vector>
using namespace std;

void devide(string s, int n, int& r) {
	for (int i = 0; i < s.size(); i++) {
		int temp = (s[i] - '0') + r * 10;
		r = temp % n;
		s[i] = temp/n + '0';
	}
}

int main() {
	string s;
	while (cin >> s) {
		if (s == "-1")
			break;
		string res = "";
		for (int i = 2; i < 10; i++) {
			int r = 0;
			devide(s, i, r);
			if (r == 0) {
				res += char(i + '0');
				res += " ";
			}
		}
		if (res.size() == 0)
			cout << "none" << endl;
		else {
			res.pop_back();
			cout << res << endl;
		}
	}
}

  

猜你喜欢

转载自www.cnblogs.com/songlinxuan/p/12466765.html