Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define MOD 666013
  4.  
  5. using namespace std;
  6.  
  7. int n, A[11], T;
  8. long long a = 1, B;
  9.  
  10. int factorial(int x)
  11. {
  12.           if(x == 0) return 1 ;
  13.           int sol = 1;
  14.           for(int i = 2; i <= x; ++i)
  15.                     sol = (1LL * sol * i) % MOD;
  16.           return sol;
  17. }
  18.  
  19. int Invers_Modular(int x)
  20. {
  21.           int sol = 1;
  22.           int putere = MOD - 2;
  23.           while(putere > 0)
  24.           {
  25.                     if(putere & 1) sol = (1LL * sol * x) % MOD;
  26.                     x = (1LL * x * x) % MOD;
  27.                     putere >>= 1;
  28.           }
  29.           return sol;
  30. }
  31.  
  32. int main()
  33. {
  34.           freopen("mygo.in", "r", stdin);
  35.           freopen("mygo.out", "w", stdout);
  36.           for(int i = 0; i <= 9; ++i)
  37.           {
  38.                     scanf("%d", &A[i]);
  39.                     T += A[i];
  40.           }
  41.           if(A[0] > 0)
  42.           {
  43.                     a = factorial(T - 1);
  44.                     a = (1LL * a * Invers_Modular(factorial(A[0]))) % MOD;
  45.                     a = (1LL * a * Invers_Modular(factorial(T - 1 - A[0]))) % MOD;
  46.                     T -= A[0];
  47.           }
  48.           else a = 1;
  49.           for(int i = 1; i <= 9; ++i)
  50.           {
  51.                     if(A[i] > 0)
  52.                     {
  53.                               B = factorial(T);
  54.                               B = (1LL * B * Invers_Modular(factorial(A[i]))) % MOD;
  55.                               B = (1LL * B * Invers_Modular(factorial(T - A[i]))) % MOD;
  56.                               a = (a * B) % MOD;
  57.                               T -= A[i];
  58.                     }
  59.           }
  60.           printf("%lld", a);
  61.           return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement