Advertisement
Guest User

Untitled

a guest
Jul 25th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. //
  2. // d.cpp -- d
  3. //
  4. // Siwakorn Sriakaokul - ping128
  5. // Written on Saturday, 27 April 2013.
  6. //
  7.  
  8. #include <cstdio>
  9. #include <iostream>
  10. #include <sstream>
  11. #include <cstdlib>
  12. #include <string>
  13. #include <vector>
  14. #include <set>
  15. #include <queue>
  16. #include <stack>
  17. #include <list>
  18. #include <cmath>
  19. #include <algorithm>
  20. #include <map>
  21. #include <ctype.h>
  22.  
  23. #define MOD 1000000009
  24.  
  25. using namespace std;
  26.  
  27. typedef long long LL;
  28.  
  29.  
  30. LL pow2(int x){
  31.     if(x == 0) return 1LL;
  32.     if(x % 2){
  33.         return (2 * pow2(x - 1)) % MOD;
  34.     } else {
  35.         LL temp = pow2(x / 2);
  36.         return (temp * temp) % MOD;
  37.     }
  38. }
  39.  
  40. LL fac[200005];
  41.  
  42. void inverse(LL a, LL b, LL *X, LL *Y){
  43.     if(b == 0){
  44.         *X = 1;
  45.         *Y = 0;
  46.     } else {
  47.         LL xx, yy;
  48.         inverse(b, a % b, &xx, &yy);
  49.         *X = yy;
  50.         *Y = xx - (a / b) * yy;
  51.     }
  52. }
  53.  
  54.  
  55. LL nCr(LL n, LL r){
  56.     LL x, y;
  57.     inverse((fac[r] * fac[n - r]) % MOD, MOD, &x, &y);
  58.     x = (x + MOD) % MOD;
  59.     return (fac[n] * x) % MOD;
  60. }
  61.  
  62. int main()
  63. {
  64.     fac[0] = 1;
  65.     for(int i = 1; i < 200005; i++ ){
  66.         fac[i] = (i * fac[i - 1]) % MOD;
  67.     }
  68.  
  69.     int n;
  70.     cin >> n;
  71.     LL ans = 0;
  72.     for(int i = 1; i < n; i++ ){
  73.         ans += (nCr(n, i) * ((pow2(i) - 1 + MOD) % MOD)) % MOD;
  74.         ans %= MOD;
  75.     }
  76.     cout << ans << endl;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement