# bzoj2134 错选单位

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

Output

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
int a[10000100];
int main()
{     int n,A,B,C;
double ans=0;
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;
a[n+1]=a[1];
for(int i=1;i<=n;i++)
ans+=double(1)/(max(a[i],a[i+1]));
printf("%0.3lf\n",ans);
return 0;
}
posted @ 2018-06-19 09:40  水题收割者  阅读(110)  评论(0编辑  收藏  举报