fork download
  1. #include<bits/stdc++.h>
  2. using namespace std ;
  3. #define faster() ios::sync_with_stdio(false); cin.tie(nullptr) ; cout.tie(nullptr);
  4. #define endl "\n"
  5. #define int long long
  6. const int MOD = 1e9 + 7 ;
  7.  
  8. void solve(){
  9. int n , x ; cin >> n >> x ;
  10. vector<int> a(n);
  11. for(int i = 0 ; i < n ; i++) cin >> a[i];
  12. int ans = a[0];
  13. for (int i = 1; i < n; i++){
  14. ans = (ans * x + a[i]);
  15. ans %= MOD ;
  16. }
  17. cout << ans << endl;
  18. }
  19.  
  20. signed main(){
  21. faster();
  22. int test ;
  23. cin >> test;
  24. while(test--) solve();
  25. }
Success #stdin #stdout 0.01s 5288KB
stdin
1
4  2

1  2  0  4
stdout
20