华为机试题 质数因子

简介

简单, 但是, 输出的格式有点错乱

code

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
 
int main() {
    long s;
    cin >> s;
    while(s != 1) {
        int i;
        for(i=2; i<=sqrt(s); ){
            if(s % i == 0) {
                s /= i;
                cout << i << " ";
                continue;
            }
            i++;
        }
        //cout << i << " " << (int)sqrt(s) << endl;
        if(i == (int)sqrt(s)+1 && s != 1){
            cout << s << " ";
            s = 1;
        }
    }
    cout << endl;
}
Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
原文地址:https://www.cnblogs.com/eat-too-much/p/14919855.html