因式分解 C++实现

void devideFactor(const int N) {
vector<int> 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<int>::iterator iter = vec.begin(); iter != vec.end(); iter++) {
cout << "  " << *iter;
}

}
阅读更多
文章标签: c++ iterator
个人分类: 数据结构与算法
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭