-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVA 10392.cpp
50 lines (49 loc) · 938 Bytes
/
UVA 10392.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<stdio.h>
#include<math.h>
#define maxx 1000005
long long prime[maxx],pp[maxx];
int main()
{
long long n,i;
int l=sqrt(maxx),j;
prime[0]=prime[1]=1;
for(i=4; i<maxx; i+=2)
{
prime[i]=1;
}
for(i=3; i<=l; i+=2)
{
if(prime[i]==0)
{
for(j=i*i; j<maxx; j+=i)
{
prime[j]=1;
}
}
}
int k=0;
for(i=2;i<maxx;i++)
{
if(prime[i]==0)
pp[k++]=i;
}
while(scanf("%lld",&n)==1)
{
if(n<0)
break;
for(i=0; i<k; i++)
{
while(n%pp[i]==0)
{
printf(" %lld\n",pp[i]);
n=n/pp[i];
}
if(n==1)
break;
}
if(n!=1)
printf(" %lld\n",n);
printf("\n");
}
return 0;
}