-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCandyLottery.cpp
More file actions
38 lines (32 loc) · 838 Bytes
/
CandyLottery.cpp
File metadata and controls
38 lines (32 loc) · 838 Bytes
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
//Candy Lottery - https://cses.fi/problemset/task/1727
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
void solve() {
int n, k;
cin >> n >> k;
double ans = 0;
for (int value = 1; value <= k; value++) {
if (value == 1) {
ans += pow(1 / (double) k, n);
continue;
}
double less_than_val = pow(value / (double) k, n);
double less_than_val_minus_one = pow((value - 1) / (double) k, n);
double prob = less_than_val - less_than_val_minus_one;
ans += value * prob;
}
cout << setprecision(6) << fixed << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}