View Code of Problem 91

#include<bits/stdc++.h>
using namespace std;
//#define N 1000
int main()
{
	int N;
	while(cin>>N) {
		int a[N+5];
		memset(a,1,sizeof(a));
		for(int i=2;i<N+5;i++) 
			for(int j=i;i*j<N+5;j++) 
				a[i*j]=0;
//		for(int i=0;i<N;i++)
//			if(a[i]) 
//				cout<<i<<endl;
		cout<<N<<"=";
		int n=N;
		int flag = 0;
		while(n!=1) {
			int i;
			for(i=2;n%i!=0||a[i]==0;i++);
			if(!flag) {
				cout<<i;
				flag=1;
			} else 
				cout<<"*"<<i;
			n/=i;
			}
		cout<<endl;
	}


	return 0;
	
}

Double click to view unformatted code.


Back to problem 91