-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminimumSumLCM_10791.cpp
89 lines (75 loc) · 1.74 KB
/
minimumSumLCM_10791.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
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define ll long long
ifstream fin("minimumSumLCM_10791.in");
ofstream fout("minimumSumLCM_10791.out");
int N = 50000;
int main()
{
vector<bool> isPrime(N + 1, true);
isPrime[0] = false, isPrime[1] = false;
vector<long long> primes;
for (long long i = 2; i <= N; ++i)
{
if (isPrime[i] == true)
{
primes.push_back(i);
for (long long j = i * i; j <= N; j += i)
{
isPrime[j] = false;
}
}
}
int T = 0;
while (true)
{
++T;
long long n = 0;
fin >> n;
if (n == 0) break;
if (n == 1)
{
fout << "Case " << T << ": 2\n";
}
else
{
long long count = 0, ans = 0;
for (int i = 0; primes[i] * primes[i] <= n; ++i)
{
long long a = 1, now = primes[i];
while (n % now == 0)
{
a *= now;
n /= now;
}
if (a > 1)
{
++count;
ans += a;
}
}
if (n > 1)
{
++count;
ans += n;
}
if (count == 1)
{
++ans;
}
fout << "Case " << T << ": " << ans << '\n';
}
}
return 0;
}