Saleh127

Lo 1328

Sep 10th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int shit=1;shit<=t;shit++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10. test
  11. {
  12. ll a[200005],k,n,c,i,j,l,ans=0,prev=0;
  13. cin>>k>>c>>n>>a[0];
  14. for(i=1;i<=n-1;i++)
  15. {
  16. a[i]=(k*a[i-1]+c)%1000007;
  17. }
  18. sort(a,a+n);
  19. for(i=1;i<=n-1;i++)
  20. {
  21. prev+=a[i-1];
  22. ans+=(a[i]*i)-prev;
  23. }
  24.  
  25. /*
  26. for(i=1;i<=n-1;i++)
  27. {
  28. ans+=(a[i]-a[i-1])*(i*(n-i));
  29. }
  30. */
  31.  
  32. cout<<"Case "<<shit<<": "<<ans<<endl;
  33. }
  34.  
  35.  
  36. return 0;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment