题解:
每一题对的概率为min(a[i],a[i+1])/a[i]/a[i+1];
即可
代码:
#include<bits/stdc++.h> using namespace std; const int N=10000005; int a[N],n,A,B,C; int main() { 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=0; for (int i=1;i<n;i++) ans+=(double)min(a[i],a[i+1])/a[i]/a[i+1]; printf("%.3lf",ans+(double)min(a[1],a[n])/a[1]/a[n]); }