AtCoder Beginner Contest 206(Sponsored by Panasonic)
AtCoder Beginner Contest 206(Sponsored by Panasonic)
A - Maxi-Buying
int main() {
IOS; int x; cin >> x; x = floor(x * 1.08);
if (x < 206) cout << "Yay!";
else if (x == 206) cout << "so-so";
else cout << ":(";
return 0;
}
B - Savings
int main() {
IOS; ll x; cin >> x;
ll s = floor(sqrt(x <<= 1));
cout << (s * (s + 1) >= x ? s : s + 1);
return 0;
}
C - Swappable
int main() {
IOS; map<int, int> st; cin >> n;
rep (i, 1, n) {
cin >> m; ++st[m];
ans += i - st[m];
}
cout << ans;
return 0;
}
D - KAIBUNsyo
int f[N], a[N];
int ff(int x) { return f[x] == x ? x : f[x] = ff(f[x]); }
void unit(int x, int y) { if ((x = ff(x)) ^ (y = ff(y))) f[y] = x; }
int main() {
IOS; cin >> n;
rep (i, 1, n) cin >> a[i], f[a[i]] = a[i];
rep (i, 1, n >> 1) {
a[i] = ff(a[i]), a[n + 1 - i] = ff(a[n + 1- i]);
if (a[i] ^ a[n + 1 - i]) unit(a[i], a[n + 1 - i]), ++m;
}
cout << m;
return 0;
}
E - Divide Both
容斥
ll c[N], a[N], ans;
int main() {
IOS; cin >> n >> m;
rep (i, 2, m >> 1)
for (int j = (n - 1) / i * i + i; j <= m; j += i) ++c[i];
per (i, m >> 1, 2) {
a[i] = c[i] * (c[i] - 1);
for (int j = i * 2; j <= m; j += i) a[i] -= a[j];
ans += a[i];
if (i >= n) ans -= c[i] - 1 << 1;
}
cout << ans;
return 0;
}