blob: e45de2b46160ec7873651bd468ab8e12ee68e94d (
plain) (
blame)
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
|
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int n;
cin >> n;
for (int i = 2; i <= n; i++)
{
//primality check
bool isPrime = true;
double temp = sqrt(i);
for (int k = 2; k <= temp; k++)
{
if (i % k == 0)
{
isPrime = false;
break;
}
}
if (!isPrime)
continue; //we don't need this number
//check how many time i devides n
int count = 0;
while (n % i == 0)
{
count++;
n /= i;
}
if (count >= 1)
{
cout << i << "^" << count << " ";
}
}
}
|