Advertisement
a53

p_a_l_i_d

a53
Oct 30th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #define Kmax 10
  3. #define MOD 1000000007
  4. #define LL long long int
  5. using namespace std;
  6. int c[2][Kmax];
  7.  
  8. void pdcomb(int n) /// folosesc doar doua linii (0 si 1)
  9. {
  10. for(int i=0;i<=Kmax;++i) /// Initializez matricea
  11. c[0][i]=c[1][i]=0;
  12. c[0][0]=c[1][0]=1; /// coloana 0
  13. for(int i=1;i<=n;++i)
  14. {
  15. for(int j=1;j<=i;++j)
  16. c[1][j]=(c[0][j]+c[0][j-1]); /// Calculez linia urmatoare (1)
  17. for(int k=0;k<=i;++k) /// copiez linia 1 in linia 0
  18. c[0][k]=c[1][k];
  19. }
  20. }
  21.  
  22. LL P(int a,int b) /// a^b logaritmic (recursiv)
  23. {
  24. if(b==0)
  25. return 1ULL;
  26. else
  27. if(b%2==0)
  28. return P((1LL*a*a)%MOD,b/2);
  29. else
  30. return 1LL*a*P((1LL*a*a)%MOD,b/2)%MOD;
  31. }
  32.  
  33. int main()
  34. {
  35. int n,m,k;
  36. LL sol;
  37. cin>>n;
  38. while(n--)
  39. {
  40. cin>>m>>k;
  41. if(m%2)
  42. ++m;
  43. pdcomb(k);
  44. if(k==1)
  45. cout<<1<<'\n';
  46. else
  47. {
  48. sol=0;
  49. for(int i=0;k>2*i;++i)
  50. sol=(sol+c[1][i]*P(k-2*i,m))%MOD;
  51. sol*=P(P(2,k-1),MOD-2)%MOD;
  52. cout<<sol%MOD<<'\n';
  53. }
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement