fork(1) download
  1. #include <bits/stdc++.h>
  2. #define endl "\n"
  3. #define mod 1000000007
  4. #define ll long long int
  5. using namespace std;
  6.  
  7. ll modin(ll a)
  8. {
  9. ll x = 1LL, y = a, b=(mod-2LL);
  10. while(b>0)
  11. {
  12. if(b&1)
  13. {
  14. x=(x*y);
  15. if (x>=mod) x=x%mod;
  16. }
  17. y = (y*y);
  18. if (y>=mod) y=y%mod;
  19. b=b>>1; // b/=2
  20. }
  21. return x;
  22. }
  23.  
  24. int main()
  25. {
  26. ios::sync_with_stdio(false);
  27. ll t;
  28. cin>>t;
  29. ll n,x,m,temp1,ans,temp2,temp3,temp4;
  30. ll a[100006];
  31. while (t--)
  32. {
  33. ans=0;
  34. temp1=0;
  35. temp2=0;
  36. temp3=0;
  37. temp4=0;
  38. cin>>n>>x>>m;
  39. for (ll i=1LL;i<=n;i++)
  40. {
  41. cin>>a[i];
  42. a[i]%=mod;
  43. }
  44. if (x==1)
  45. cout<<(a[1]%mod)<<endl;
  46. else if (m==1)
  47. {
  48. for (ll i=1LL;i<=x;i++)
  49. {
  50. ans = (ans + (a[i]%mod))%mod;
  51. }
  52. }
  53. else
  54. {
  55. temp1 = 1LL;
  56. ans = ((temp1*(a[x]%mod))%mod);
  57. temp3 = m;
  58. temp4 = 1LL;
  59. for (ll i=1LL;i<x;i++)
  60. {
  61. temp2 = (((temp3%mod)*(modin(temp4)%mod))%mod);
  62. temp1 = (temp1*temp2)%mod;
  63. ans = ((ans+((temp1*(a[x-i]%mod))%mod))%mod);
  64. temp3++;
  65. temp4++;
  66. }
  67. cout<<(ans%mod)<<endl;
  68. }
  69. }
  70. return 0;
  71. }
  72.  
Success #stdin #stdout 0s 4116KB
stdin
2
3 2 3
1 2 3
3 3 3 
1 2 3
stdout
5
15