// http://www.spoj.com/problems/PTIME/
#include<stdio.h>
int sieve[100010]={0};
long prime_table() {
int i, j;
for (i = 2; i <=50000; i+= 2)
sieve[i]=1;
for (i = 3; i <=50000; i += 2){
if (sieve[i]==0){
for (j=i; (j*i) <=50000; j += 2){
sieve[j*i] = 1;
}
}
}
}
int main(){
prime_table();
long long a,t,n,i,j,u,x,v,p,s;
scanf("%lld",&n);
a=n;x=0;p=2;
while(a){
a=n;
x+=(n/p);
p*=2;
a/=p;
}
printf("%lld^%lld",2,x);
for(i=3;i<=n;i+=2){
if(sieve[i]==0){
a=n;x=0;p=i;
while(a){
a=n;
x+=(n/p);
p*=i;
a/=p;
}
printf(" * %lld^%lld",i,x);
}
}
printf("\n");
return 0;
}
#include<stdio.h>
int sieve[100010]={0};
long prime_table() {
int i, j;
for (i = 2; i <=50000; i+= 2)
sieve[i]=1;
for (i = 3; i <=50000; i += 2){
if (sieve[i]==0){
for (j=i; (j*i) <=50000; j += 2){
sieve[j*i] = 1;
}
}
}
}
int main(){
prime_table();
long long a,t,n,i,j,u,x,v,p,s;
scanf("%lld",&n);
a=n;x=0;p=2;
while(a){
a=n;
x+=(n/p);
p*=2;
a/=p;
}
printf("%lld^%lld",2,x);
for(i=3;i<=n;i+=2){
if(sieve[i]==0){
a=n;x=0;p=i;
while(a){
a=n;
x+=(n/p);
p*=i;
a/=p;
}
printf(" * %lld^%lld",i,x);
}
}
printf("\n");
return 0;
}
No comments:
Post a Comment