PAT A1059. Prime Factors (25)

Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p1^k1* p2^k2 *…*pm^km.

Input Specification:

Each input file contains one test case which gives a positive integer N in the range of long int.

Output Specification:

Factor N in the format N = p1^k1 * p2^k2 *…*pm^km, where pi's are prime factors of N in increasing order, and the exponent ki is the number of pi -- hence when there is only one pi, ki is 1 and must NOT be printed out.

Sample Input:
97532468
Sample Output:

97532468=2^2*11*17*101*1291


对于这种将一个数进行质数分离的,思想就是从小到大不断地寻找其因子,并对原数进行改变,当其无法被除时,最后一个因子就是被改变的原数自己本身。

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define Max 100010
int P[Max],flag=0;
bool Prime_is(int n)
{
	if(n<=1) return false ;
	else {
	int  sqr =(int)sqrt(1.0 * n);
	for(int i=2;i<=sqr;i++)
    	{
			if(n%i==0)
				return false ;
	    }
	return true;
	}
}
void Prime_t()
{
	for(int i=2;i1){
		printf("^%d",p[i].num);}
	   }
	}
    system("pause");
    return 0;
}

你可能感兴趣的:(PAT)