这个怎算啊。。
老是算不出来。。
前几天编的!!只是:90=2*3^2*5(3的2次方)
#include <stdio.h>
#include <math.h>
void primnum(long num)
{
long i,index=2,ncount=0,sqr=(long)sqrt(double(num));
for(i=index;i<=sqr;++i)
{
while(num%i==0)
{
num/=i;
++ncount;
index=i;
sqr=(long)sqrt(double(num));
}
if(ncount==1)
{
printf("%ld*",i);
ncount=0;
}
if(ncount>1)
{
if(num==1)
{
printf("%ld^%ld",i,ncount);
goto end;
}
else
{
printf("%ld^%ld*",i,ncount);
ncount=0;
}
}
}
if(ncount==0||index>sqr)
{
printf("%ld\n",num);
}
end: return;
}
int main()
{
long num;
while(scanf("%ld",&num)!=EOF)
{
printf("%ld = ",num);
if(num<2)return 1;
else primnum(num);
}
return 0;
}
#include <stdio.h>
#include <math.h>
#define LEN 100000
int Primes[LEN]={0};
void Eratosthenes(int n){
int i;
int j,k=0;
int a[LEN];
for(i=1;i<=n;i++)
a[i]=i;
for(i=2;i<sqrt(n);i++)
for(j=i+1;j<=n;j++) {
if (a[i]!=0&&a[j]!=0)
if (a[j]%a[i]==0)
a[j]=0;
else
continue;
}
for(i=2;i<=n;i++){
if (a[i]!=0){
Primes[k]=a[i];
k++;
}
else
continue;
}
return ;
}
void Remov(int n){
int i;
for(i=0;Primes[i]!=0;){
if(n%Primes[i]==0){
printf("%d*",Primes[i]);
n/=Primes[i];
continue;
}
else
i++;
}
return ;
}
int main(void){
int n;
scanf("%d",&n);
Eratosthenes(n);
Remov(n);
return 0;
}