fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. long long n, m = 1e9 + 7;
  7. cin >> n;
  8. long long res;
  9. if(n == 1){
  10. res=0;
  11.  
  12. }else{
  13. res = (1 * (n % 2 == 0) + -1 * (n % 2 == 1));
  14. long long prev = res;
  15. for (long long i = n - 1; i >1; i--) {
  16. res += prev * (-i - 1 +m) % m;
  17. prev *= (-i - 1);
  18. prev = (prev + m) % m;
  19. res = (res + m) % m;
  20. }
  21. }
  22. cout << res;
  23. return 0;
  24.  
  25. }
Success #stdin #stdout 0.06s 15232KB
stdin
10000000
stdout
824182295