Cod sursa(job #1853958)
| Utilizator | Data | 22 ianuarie 2017 11:31:52 | |
|---|---|---|---|
| Problema | Hashuri | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <cstdio>
#include <algorithm>
using namespace std;
int n, k, q, x, y, z;
int a[1000001];
int main()
{
freopen("beri.in", "r", stdin);
freopen("beri.out", "w", stdout);
scanf("%d %d", &n, &k);
scanf("%d%d%d%d", &q, &x, &y, &z);
a[1] = q;
for(int i = 2; i <= n ; ++i)
a[i] = 1LL * (1LL * a[i - 1] * x + y) % z + k;
nth_element(a + 1, a + n - k + 1, a + n + 1);
int ad = 0;
long long Sol = 0;
for(int i = n; i > n - k ; --i){
Sol = Sol + a[i] - ad;
++ad;
}
printf("%lld", Sol);
return 0;
}
