Advertisement
Fabio99

Untitled

Feb 9th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <assert.h>
  3. using namespace std;
  4.  
  5. const int MAXN=1000000;
  6.  
  7. int enumera(int N, int M) {
  8. int i, j;
  9. long long int A[MAXN+1];
  10. A[0]=-1;
  11. A[1]=0;
  12. long long int somma=-1;
  13. for (i=2;i<N+1;i++)
  14. {
  15. long long int tmp=(A[i-1]*i-somma);
  16. A[i]=tmp;
  17. somma+=A[i];
  18. }
  19. return A[N]%M;
  20. }
  21.  
  22.  
  23. int main() {
  24. FILE *fr, *fw;
  25. int N, M;
  26.  
  27. fr = fopen("input.txt", "r");
  28. fw = fopen("output.txt", "w");
  29. assert(2 == fscanf(fr, "%d%d", &N, &M));
  30.  
  31. fprintf(fw, "%d\n", enumera(N, M));
  32. fclose(fr);
  33. fclose(fw);
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement