ANS=Σ1/max(a[i],a[i%n+1])。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define maxn 10000050 using namespace std; int n,A,B,C,a[maxn]; double ans=0; int main() { scanf("%d%d%d%d%d",&n,&A,&B,&C,&a[1]); for (register int i=2;i<=n;i++) a[i]=((long long)a[i-1]*A+B)%100000001; for (register int i=1;i<=n;i++) a[i]=a[i]%C+1; for (register int i=1;i<=n-1;i++) ans+=1.0/max(a[i],a[i+1]); ans+=1.0/max(a[1],a[n]); printf("%.3lf\n",ans); return 0; }