对(a_i与a_{i+1})的大小关系进行讨论
[a_i<a_{i+1} E=frac{a_i}{a_{i+1}} * frac{1}{a_i}=frac{1}{a_{i+1}} \
a_i=a_{i+1} E=frac{1}{a_{i+1}} \
a_i>a_{i+1} E=frac{a_{i+1}}{a_i}*frac{1}{a_{i+1}}=frac{1}{a_{i}}
]
所以 $$ ans=sum_{i=1}^{n}frac{1}{max(a_i , a_{i+1})} $$
const int N = 1e7 + 79;
int n, A, B, C;
int a[N];
inline void read() {
scanf("%d%d%d%d%d", &n, &A, &B, &C, a + 1);
for (int i = 2; i <= n; i++)
a[i] = ((long long) a[i - 1] * A + B) % 100000001;
for (int i = 1; i <= n; i++)
a[i] = a[i] % C + 1;
}
double ans;
int main() {
read();
a[n + 1] = a[1];
rep(i, 1, n) {
ans += 1.0 / (1.0*max(a[i], a[i + 1]) );
}
std::cout << std::fixed << std::setprecision(3) << ans << '
';
return 0;
}