现在的位置: 首页 > 综合 > 正文

素因数分解

2013年12月15日 ⁄ 综合 ⁄ 共 432字 ⁄ 字号 评论关闭

素因数又写,,,

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

贴出代码:

#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;
}

抱歉!评论已关闭.