码迷,mamicode.com
首页 > 其他好文 > 详细

cf 1139D - Steps to One

时间:2019-03-23 22:08:38      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:def   链接   cin   mod   names   +=   one   ==   http   

题目链接: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

标签:def   链接   cin   mod   names   +=   one   ==   http   

原文地址:https://www.cnblogs.com/albert-biu/p/10585829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!