# 【刷题】BZOJ 2134 单选错位

## Input

n很大，为了避免读入耗时太多，

// for pascal

for i:=2 to n do q[i] := (int64(q[i-1]) * A + B) mod 100000001;

for i:=1 to n do q[i] := q[i] mod C + 1;

// for C/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;

n和a的含义见题目描述。

2≤n≤10000000, 0≤A,B,C,a1≤100000000

3 2 0 4 1

## Sample Output

1.167
【样例说明】
a[] = {2,3,1}

{1,1,1} {1,1,1} 3 1/6
{1,2,1} {1,1,2} 1 1/6
{1,3,1} {1,1,3} 1 1/6
{2,1,1} {1,2,1} 1 1/6
{2,2,1} {1,2,2} 1 1/6
{2,3,1} {1,2,3} 0 1/6

## Solution

$\frac{\min\{a_i,a_{i-1}\}}{a_i*a_{i-1}}=\frac{1}{\max \{a_i,a_{i-1}\}}$

#include<bits/stdc++.h>
#define ui unsigned int
#define ll long long
#define db double
#define ld long double
#define ull unsigned long long
const int Mod=1e8+1;
int n,A,B,C,st,pre,now;
db ans;
template<typename T> inline void read(T &x)
{
T data=0,w=1;
char ch=0;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')w=-1,ch=getchar();
while(ch>='0'&&ch<='9')data=((T)data<<3)+((T)data<<1)+(ch^'0'),ch=getchar();
x=data*w;
}
template<typename T> inline void write(T x,char ch='\0')
{
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
if(ch!='\0')putchar(ch);
}
template<typename T> inline void chkmin(T &x,T y){x=(y<x?y:x);}
template<typename T> inline void chkmax(T &x,T y){x=(y>x?y:x);}
template<typename T> inline T min(T x,T y){return x<y?x:y;}
template<typename T> inline T max(T x,T y){return x>y?x:y;}
int main()
{