-
Notifications
You must be signed in to change notification settings - Fork 185
/
Copy pathe.cc
86 lines (84 loc) · 1.68 KB
/
e.cc
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
// https://codeforces.com/contest/1406/problem/E
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
vector<bool> primesieve(n + 1, true);
primesieve[0] = false;
primesieve[1] = false;
for (int i = 2; i <= n; i++)
if (primesieve[i])
for (int j = i * 2; j <= n; j += i) primesieve[j] = false;
vector<ll> primes;
for (int i = 2; i <= n; i++)
if (primesieve[i]) primes.push_back(i);
int r = 1, x;
int i = 0;
while (i < primes.size()) {
ll p = primes[i];
if (p * p > n) break;
i++;
ll q = p;
while (q <= n) {
cout << "B " << q << endl;
cin >> x;
if (p == q) {
cout << "A " << q << endl;
cin >> x;
}
if (!x) {
q /= p;
break;
}
q *= p;
}
if (q > n) q /= p;
r *= q;
}
cout << "A 1" << endl;
int count;
cin >> count;
vector<ll> pending;
while (i < primes.size()) {
ll p = primes[i];
cout << "B " << p << endl;
cin >> x;
if (x > 1) r *= p;
pending.push_back(p);
i++;
count--;
if (pending.size() >= 100) {
cout << "A 1" << endl;
cin >> x;
if (x != count) {
for (int q : pending) {
cout << "A " << q << endl;
cin >> x;
if (x) {
r *= q;
break;
}
}
pending.clear();
break;
}
pending.clear();
}
}
if (pending.size()) {
cout << "A 1" << endl;
cin >> x;
if (x != count)
for (int q : pending) {
cout << "A " << q << endl;
cin >> x;
if (x) {
r *= q;
break;
}
}
}
cout << "C " << r << endl;
}