Advertisement
erfanul007

LOJ 1328

Dec 16th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef unsigned long long int ull;
  5. typedef long long int ll;
  6. typedef vector<int> vi;
  7. typedef vector<ll> vll;
  8. typedef vector<vi> vvi;
  9. typedef pair<int,int > pii;
  10. typedef vector< pii > vpii;
  11. typedef set<int> sti;
  12.  
  13. #define sc scanf
  14. #define pf printf
  15. #define sci(n) scanf("%d",&n)
  16. #define scii(n,m) scanf("%d %d",&n,&m)
  17. #define scl(n) scanf("%lld",&n)
  18. #define scd(n) scanf("%lf",&n)
  19. #define scs(s) scanf("%s",s)
  20. #define pfi(n) printf("%d",n)
  21. #define pfl(n) printf("%lld",n)
  22. #define pff(n) cout<<n
  23. #define line printf("\n")
  24. #define spc printf(" ")
  25. #define clr(a,x) memset(a,x,sizeof(a))
  26. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  27. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  28. #define cspf(i) printf("Case %d: ", i)
  29. #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
  30. #define pb push_back
  31. #define mp make_pair
  32. #define ff first
  33. #define ss second
  34. #define all(v) v.begin(),v.end()
  35. #define rall(v) v.rbegin(),v.rend()
  36. #define read() freopen("input.txt", "r", stdin)
  37. #define write() freopen("output.txt", "w", stdout)
  38. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
  39. /// Constants
  40. #define eps 1e-9
  41. #define PI acos(-1.0) // 3.1415926535897932
  42. #define MAX 1e9
  43. #define MOD 1000007
  44.  
  45. ll GCD(ll a, ll b) { return b == 0 ? a : GCD(b , a % b); }
  46. ll LCM(ll a, ll b) { return a * (b/GCD(a, b)); }
  47.  
  48. ll a[100005],cum[100005];
  49.  
  50. int main()
  51. {
  52. read();
  53. write();
  54.  
  55. int t;
  56. sci(t);
  57. loop(ca,1,t){
  58. ll k,c,n;
  59. sc("%lld %lld %lld %lld",&k,&c,&n,&a[0]);
  60. loop(i,1,n-1) a[i]=((k*a[i-1])+c)%MOD;
  61. sort(a,a+n);
  62. clr(cum,0);
  63. cum[0]=a[0];
  64. loop(i,1,n-1) cum[i]=(cum[i-1]+a[i]);
  65. ll sum=0LL;
  66. loop(i,1,n-1){
  67. ll x = cum[n-1]-cum[i-1];
  68. ll y = ((n-i)*a[i-1]);
  69. sum+=(x-y);
  70. }
  71. cspf(ca);
  72. pfl(sum);
  73. line;
  74.  
  75. }
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement