fork download
  1. #include <iostream>
  2. #include<stdio.h>
  3. using namespace std;
  4.  
  5. //long long int D[1000001], S[1000001];
  6.  
  7. int main()
  8. {
  9. int T;
  10. cin >> T;
  11. while(T--)
  12. {
  13. long long H, A, B, IND, m;
  14. int n;
  15. cin >> H >> n >> m >> A >> B >> IND;
  16. long long int D[m+1];
  17. for(int i = 0; i < m; i++)
  18. cin >> D[i];
  19. long long int S[n+2];
  20. S[0] = 0;
  21. for(int i = 1; i <n; i++)
  22. {
  23. S[i] = S[i-1] + D[IND];
  24. IND = (IND * A + B) % m;
  25. }
  26. double area=(S[n-1] * H);
  27. printf("%.1lf\n", area / 2);
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 3348KB
stdin
2
5
2 2
0 1 0
10 10
10
10 5
2 3 4
2 5 1 1 4
stdout
25.0
140.0