Advertisement
tumaryui

Untitled

Jul 3rd, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define pii pair<int, int>
  4. using namespace std;
  5.  
  6. const int mod = 1e9 + 7;
  7.  
  8. int bpow(int a, int n) {
  9. int res = 1;
  10. while(n) {
  11. if(n & 1) {
  12. res *= a;
  13. res %= mod;
  14. n--;
  15. } else {
  16. a *= a;
  17. a %= mod;
  18. n /= 2;
  19. }
  20. }
  21. return res % mod;
  22. }
  23.  
  24. int C(int k, int n) {
  25. int res = 1;
  26. for(int i = 1; i <= k; i++) {
  27. res *= (n - k + i);
  28. res %= mod;
  29. res *= bpow(i, mod - 2);
  30. res %= mod;
  31. }
  32. return res;
  33. }
  34.  
  35. int phi(int n) {
  36. int res = n;
  37. for(int i = 2; i * i <= n; i++) {
  38. if(n % i == 0) {
  39. while(n % i == 0) {
  40. n /= i;
  41. }
  42. res -= res / i;
  43. }
  44. }
  45. if(n > 1) {
  46. res -= res / n;
  47. }
  48. return res;
  49. }
  50.  
  51. main() {
  52. int k, n;
  53. cin >> k >> n;
  54. int c = C(k, n);
  55. cout << phi(c) << endl;;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement