您的位置:首页 > 其它

素因数分解

2013-02-03 19:52 176 查看
素因数又写,,,

<我和丈母娘的十年生活> 很好看呀呵呵

贴出代码:

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <string>

using namespace std;

int main()
{
int N;
while (cin >> N)
{
int temp = N;
cout << N << "=";
int cnt = 0;
int flag = 0;
for (int i = 2; i <= sqrt(temp * 1.0); i++)
{
while (temp % i == 0)
{
flag++;
temp = temp / i;
if (!cnt)
{
cnt++;
cout << i;
}
else
{
cout << "*" << i;
}
}
}
if(flag != 0 && temp != 1)
{
cout << "*" << temp;
}
else if (flag == 0 && temp != 1)
{
cout << temp;
}
cout << endl;
}
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: