cf 1139D - Steps to One
Posted albert-biu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cf 1139D - Steps to One相关的知识,希望对你有一定的参考价值。
题目链接:https://codeforces.com/contest/1139/problem/D
#include "bits/stdc++.h" using namespace std; typedef long long ll; const int mod = 1e9 + 7; const int maxn = 1e5 + 100; ll mu[maxn]; int vis[maxn]; ll mua[maxn]; ll pow_mod(ll a, ll b) { ll ret = 1; while (b) { if (b & 1) ret = ret * a % mod; a = a * a % mod; b >>= 1; } return ret; } ll inv(ll x) { return pow_mod(x, mod - 2); } int main() { ll m; cin >> m; mu[1] = 1; for (int i = 1; i <= m; i++) mu[i] = 1; for (int i = 2; i <= m; i++) { if (!vis[i]) { mu[i] = -1; for (int j = i + i; j <= m; j += i) { vis[j] = 1; if ((j / i) % i == 0) mu[j] = 0; else mu[j] *= -1; } } } ll ans = 1; for (int i = 2; i <= m; i++) { if (mu[i] != 0) { ans = ans - mu[i] * (m / i) * inv(m - m / i); } } cout << (ans % mod + mod) % mod << endl; return 0; }
以上是关于cf 1139D - Steps to One的主要内容,如果未能解决你的问题,请参考以下文章
(每日一题)CF1139D Steps to One && 2021年天梯赛 L3-3 可怜的简单题(期望,莫比乌斯反演,杜教筛)
codeforces#1139D. Steps to One (概率dp+莫比乌斯)
9 easy steps to create custom ISO RHEL/CentOS 8
9 easy steps to create custom ISO RHEL/CentOS 8