Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define pb push_back
- #define pii pair<int, int>
- using namespace std;
- const int mod = 1e9 + 7;
- int bpow(int a, int n) {
- int res = 1;
- while(n) {
- if(n & 1) {
- res *= a;
- res %= mod;
- n--;
- } else {
- a *= a;
- a %= mod;
- n /= 2;
- }
- }
- return res % mod;
- }
- int C(int k, int n) {
- int res = 1;
- for(int i = 1; i <= k; i++) {
- res *= (n - k + i);
- res %= mod;
- res *= bpow(i, mod - 2);
- res %= mod;
- }
- return res;
- }
- int phi(int n) {
- int res = n;
- for(int i = 2; i * i <= n; i++) {
- if(n % i == 0) {
- while(n % i == 0) {
- n /= i;
- }
- res -= res / i;
- }
- }
- if(n > 1) {
- res -= res / n;
- }
- return res;
- }
- main() {
- int k, n;
- cin >> k >> n;
- int c = C(k, n);
- cout << phi(c) << endl;;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement