-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFACT0.cpp
61 lines (61 loc) · 1.21 KB
/
FACT0.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
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
std::vector<bool>b(100000001,true);
std::vector<long int>a(10000001,0);
void Calcprimes ()
{
long int i,j,k;
a[0]=2;
k=1;
for (i=3;i<=10000;i+=2)
{
if (b[i]==true)
{
for (j=i*i;j<=100000000;j+=2*i)
b[j]=false;
}
}
for (i=3;i<=100000000;i+=2)
if (b[i]==true)
a[k++]=i;
}
int main()
{
long long int n;
long int count1,i,l;
Calcprimes();
while (1)
{
scanf ("%lld",&n);
if (n==0)
break;
if (n==1)
{
printf ("1^1\n");
continue;
}
l=sqrt(n);
for (i=0;a[i]<=l;i++)
{
if (n%a[i]==0)
{
count1=0;
while (n%a[i]==0)
{
count1++;
n/=a[i];
}
printf ("%ld^%ld ",a[i],count1);
}
if (n==1)
break;
}
if (n>1)
printf ("%lld^1",n);
printf ("\n");
}
return 0;
}