Advertisement
a53

B-FlippedCards2

a53
Sep 10th, 2022
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <fstream>
  2. #define mod 100000469
  3. #define LL long long
  4. using namespace std;
  5. long long fact[1000002],invers[1000002],inversfactorial[1000002];
  6.  
  7. LL solve(int x,int y)
  8. {
  9. return (((fact[x-1]*y)%mod)*inversfactorial[x-y])%mod;
  10. }
  11.  
  12. int main()
  13. {
  14. fact[0]=fact[1]=1;
  15. invers[0]=invers[1]=1;
  16. inversfactorial[0]=inversfactorial[1]=1;
  17. for(LL i=2;i<=1000001;++i)
  18. {
  19. fact[i]=(i*fact[i-1])%mod;
  20. invers[i]=(invers[mod%i]*(mod-(mod/i)))%mod;
  21. inversfactorial[i]=(invers[i]*inversfactorial[i-1])%mod;
  22. }
  23. ifstream fin("flipc2.in");
  24. int n;
  25. fin>>n;
  26. /// (x-1)!y/(x-y)!
  27. ofstream fout("flipc2.out");
  28. for(int i=1;i<=n;++i)
  29. {
  30. int y,x;
  31. fin>>x>>y;
  32. fout<<solve(x,y)<<'\n';
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement