就是求前后两个答案一样的概率:
(1/a[i])*(1/a[i+1])*min(a[i],a[i+1])->1.0/max(a[i],a[i+1])
#include<cstdio>
#include<cstring>
#include<iostream>
#define maxn 10000021
using namespace std;
int n,a[maxn];
void pre(){
int A,B,C;
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(){
pre();
for(int i=1;i<=n;i++){
ans+=1.0/max(a[i],a[i%n+1]);
}printf("%.3lf",ans);
return 0;
}