fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. long long mod = 1000000007;
  7. long long N;
  8.  
  9. long long solve(vector<long long>E) {
  10. vector<long long>C; long long sum = 1, B = 0;
  11. for (int i = 0; i < E.size(); i++) {
  12. C.push_back((N / E[i]) - B); sum *= ((N / E[i]) - B); sum %= mod;
  13. B = (N / E[i]);
  14. }
  15.  
  16. long long cx = 1;
  17. for (int i = (int)E.size() - 1; i >= 0; i--) {
  18. for (int j = 0; j < C[i] - 1; j++) { sum *= cx; sum %= mod; cx++; }
  19. cx++;
  20. }
  21. return sum;
  22. }
  23.  
  24. int main() {
  25. cin >> N;
  26. vector<long long>V; V.push_back(1);
  27. while (V[V.size() - 1] * 2LL <= N) V.push_back(V[V.size() - 1] * 2LL);
  28. reverse(V.begin(), V.end());
  29.  
  30. long long P1 = solve(V);
  31. long long sum = P1;
  32.  
  33. if (3LL * V[0] <= 2LL * N) {
  34. for (int i = 1; i <= (int)V.size() - 1; i++) {
  35. vector<long long>V2 = V;
  36. for (int j = 0; j < i; j++) V2[j] = 3LL * V2[j] / 2LL;
  37.  
  38. long long P2 = solve(V2);
  39. sum += P2; sum %= mod;
  40. }
  41. }
  42. cout << sum << endl;
  43. return 0;
  44. }
Success #stdin #stdout 0s 15240KB
stdin
8
stdout
240