#include<iostream.h>
#include<conio.h>
#include<process.h>
int isprime(int
n)
{
for(int i=2;i<=n/2;i++)
if(n%i==0)
return 0;
return 1;
}
void main()
{
clrscr();
int n;
cout<<"ENTER NUMBER : ";
cin>>n;
int prime[50]={2,3};
int i=5,cntr=2,loop=0;
if(isprime(n))
{
cout<<"1 and "<<n;
getch();
exit(0);
}
while(i<=n/2)
{
int temp;
temp=isprime(i);
if(temp==1)
prime[cntr++]=i;
if(loop%2==0)
i+=2;
else
i+=4;
loop++;
}
int factor[50]={0};
for(int j=0;j<cntr;)
{
if(n%prime[j]==0)
{
factor[j]++;
n/=prime[j];
}
else
j++;
}
for(j=0;j<cntr;j++)
if(factor[j]!=0)
cout<<"\n"<<prime[j]<<" "<<factor[j];
getch();
}
No comments:
Post a Comment