因式分解 C++实现

void devideFactor(const int N) {
vector vec;
int curVal = N;
int factor = 2;
int outerCycle = 0;
int innerCycle = 0;
for (int factor = 2; curVal > 1 && factor <= sqrt((double)curVal); factor++) {
cout << "curVal:  " << curVal << endl;
outerCycle++;
while (curVal > 1 && factor <= curVal) {
innerCycle++;
if ( curVal % factor != 0)  break;
cout << factor << endl;
vec.push_back(factor);
curVal = curVal / factor;

}

}
cout << "outerCycle: " << outerCycle << endl;
cout << "innerCycle: " << innerCycle << endl;
for (vector::iterator iter = vec.begin(); iter != vec.end(); iter++) {
cout << "  " << *iter;
}

}

你可能感兴趣的:(数据结构与算法)