-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalternateTask_UVA11728OJ.cpp
87 lines (71 loc) · 1.56 KB
/
alternateTask_UVA11728OJ.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
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
const int N = 1000;
int divSum(int n, vector<int> & primes)
{
int size0 = primes.size(), ans = 1;
for (int i = 0; primes[i] * primes[i] <= n; ++i)
{
int pf = primes[i], _pow = 0;
while (n % pf == 0)
{
n /= pf;
++_pow;
}
ans *= (int)(pow((double)pf, _pow + 1.0) - 1) / (pf - 1);
}
if (n > 1)
{
ans *= (int)(pow((double)n, 2.0) - 1) / (n - 1);
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
vector<bool> isPrime(N, true);
isPrime[0] = false, isPrime[1] = false;
vector<int> primes;
for (int i = 2; i <= N; ++i)
{
if (isPrime[i] == true)
{
primes.push_back(i);
for (int j = i * i; j <= N; j += i)
{
isPrime[j] = false;
}
}
}
vector<int> ans(1001, -1);
for (int n = 1; n <= 1000; ++n)
{
int res = divSum(n, primes);
if (res <= 1000)
{
ans[res] = n;
}
}
int C = 0;
while (true)
{
++C;
int n = 0;
cin >> n;
if (n == 0) break;
cout << "Case " << C << ": " << ans[n] << '\n';
}
cout.flush();
return 0;
}