Advertisement
a53

palid_fara_NM

a53
Jul 27th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #define Kmax 10
  3. #define MOD 1000000007
  4. using namespace std;
  5. int c[2][Kmax];
  6.  
  7. void pdcomb(int n) /// folosesc doar doua linii (0 si 1)
  8. {
  9. for(int i=0;i<=Kmax;++i)
  10. c[0][i]=c[1][i]=0;
  11. c[0][0]=c[1][0]=1; /// coloana 0
  12. for(int i=1;i<=n;++i)
  13. {
  14. for(int j=1;j<=i;++j)
  15. c[1][j]=(c[0][j]+c[0][j-1]);
  16. for(int k=0;k<=i;++k)
  17. c[0][k]=c[1][k];
  18. }
  19. }
  20.  
  21. int P(int a,int b)
  22. {
  23. if(b==0)
  24. return 1;
  25. else
  26. if(b%2==0)
  27. return P((a*a)%MOD,b/2);
  28. else
  29. return a*P((a*a)%MOD,b/2)%MOD;
  30. }
  31.  
  32. int main()
  33. {
  34. int n,m,k;
  35. unsigned int sol;
  36. cin>>n;
  37. pdcomb(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. if(k==2)
  48. cout<<P(2,m-1)%MOD<<'\n';
  49. else
  50. {
  51. sol=0;
  52. for(int i=0;k>2*i;++i)
  53. sol+=(1ULL*c[1][i]*P(k-2*i,m))%MOD;
  54. cout<<(sol/P(2,k-1))%MOD<<'\n';
  55. }
  56. }
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement