From ac8c20e01b7bea9570c859efe5061765d804a50f Mon Sep 17 00:00:00 2001 From: MD Date: Wed, 30 Oct 2024 18:10:18 -0700 Subject: [PATCH] 20241030 md's submission for cf621c (#8022) --- .../10/1030/personal_submission/cf621c_md.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 daily_problems/2024/10/1030/personal_submission/cf621c_md.cpp diff --git a/daily_problems/2024/10/1030/personal_submission/cf621c_md.cpp b/daily_problems/2024/10/1030/personal_submission/cf621c_md.cpp new file mode 100644 index 0000000000..7ed78f0349 --- /dev/null +++ b/daily_problems/2024/10/1030/personal_submission/cf621c_md.cpp @@ -0,0 +1,27 @@ +// 1030 +#include +using i64 = long long; + +int main() { + std::ios::sync_with_stdio(false); + std::cin.tie(nullptr); + + int n, p; + std::cin >> n >> p; + std::vector probs(n); + for (int i = 0; i < n; ++i) { + int left, right; + std::cin >> left >> right; + probs[i] = 1.0 * (right / p - (left - 1) / p) / (right - left + 1); + } + + double ret = 0; + for (int i = 0; i < n; ++i) { + auto next = (i + 1) % n; + ret += probs[i] + probs[next] - probs[i] * probs[next]; + } + + std::cout << std::fixed << std::setprecision(10) << ret * 2000 << '\n'; + + return 0; +} \ No newline at end of file