解题思路
概率期望,如果相邻两个位置相等则修改后仍然正确,所以我们每次只需要
取相邻两位的最小值去除以两位相乘,最后可以化简为1/最大值。代码
#includeusing namespace std;const int MAXN = 1e7+2;int n,m,A,B,C;int a[MAXN];double ans;int main(){ scanf("%d%d%d%d%d",&n,&A,&B,&C,a+1); a[2]=a[1]%C+1; for (register int i=2;i<=n;i++){ a[i] = ((long long)a[i-1] * A + B) % 100000001; a[i] = a[i] % C + 1; double mx=max(a[i],a[i-1]); ans+=1.0/mx; } ans+=1.0/(double)max(a[1],a[n]); printf("%.3lf",ans);}