Information
- ID
- 1550
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 2
- Tags
- # Submissions
- 20
- Accepted
- 15
- Uploaded By
核心:(a / b) % p = (a * b ^p-2^ ) % p
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n;
const ll mod=1e9+7;
ll ksm(ll x, ll n){
x %= mod;
ll res = 1;
while(n > 0){
if(n&1) res = ((res%mod) * (x%mod))%mod;
x = ((x%mod) * (x%mod))%mod;
n >>= 1;
}
return res%mod;
}
int main(){
cin >> n;
cout << (ksm(n, mod-2) % mod);
return 0;
}
By signing up a 追梦算法网 universal account, you can submit code and join discussions in all online judging services provided by us.