-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy path1062B-Math.cpp
76 lines (73 loc) · 1.33 KB
/
1062B-Math.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
written by Pankaj Kumar.
country:-INDIA
*/
#include <bits/stdc++.h>
using namespace std;
int solve()
{
int n;
cin >> n;
map<int, int> factor;
int temp = n, ans = 1;
int maxo = 0;
for (int i = 2; i <= int(n); i++)
{
if (temp % i == 0)
{
ans *= i;
while (temp % i == 0)
{
temp /= i;
factor[i]++;
}
}
}
cout << ans << " ";
int count = 0, count2 = 0;
while (1)
{
maxo = 0;
for (auto x : factor)
{
maxo = max(maxo, x.second);
}
// if you use maxo !=1 then it will give you tle, due to n=1 case
if (maxo > 1)
{
count++;
for (auto x : factor)
{
if (x.second % 2 == 0)
{
factor[x.first] /= 2;
}
else
{
factor[x.first]++;
factor[x.first] /= 2;
count2++;
}
}
}
else
{
break;
}
}
if (count2)
{
count++;
}
cout << count << endl;
return 0;
}
int main()
{
int testCase = 1;
while (testCase--)
{
solve();
}
return 0;
}