QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#176690#5377. $N$ 门问题Conviction0 0ms0kbC++141.0kb2023-09-11 21:34:312023-09-11 21:34:32

Judging History

你现在查看的是最新测评结果

  • [2023-09-11 21:34:32]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-09-11 21:34:31]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#define gc getchar()
using namespace std;
const int mm=1100;
double val[20]={0,0,0.5,0.666667,0.625,0.466667,0.416667,0.342857,0.291667,0.253968,0.225};
__int128 a[mm],b[mm];
__int128 read()
{
	__int128 ans=0;char ch=gc;
	while(ch<'0' || ch>'9') ch=gc;
	while(ch>='0' && ch<='9') ans=(ans<<3)+(ans<<1)+(ch^48),ch=gc;
	return ans; 
}
void exgcd(__int128 a,__int128 b,__int128 &x,__int128 &y)
{
	if(b==0)
	{
		x=1,y=0;
		return ;
	}
	exgcd(b,a%b,x,y);
	__int128 res=x;
	x=y,y=res-a/b*y;
}
int main() {
	freopen("door1.in","r",stdin);
	freopen("door.out","w",stdout);
	int m=read();
	for(int i=1;i<=m;i++) b[i]=read(),a[i]=read();
	__int128 M=a[1],ans=b[1];
	for(int i=2;i<=m;i++)
	{
		__int128 d=__gcd(M,a[i]),tmp=(b[i]-ans%a[i]+a[i])%a[i],x,y;
		if(tmp%d!=0) return puts("error"),0;
		exgcd(M,a[i],x,y);
		ans+=(tmp/d*x*M),M*=a[i]/d;
		ans=(ans%M+M)%M;
	}
	if(ans<2) return puts("error"),0;
	if(ans>10) return puts("0.000000"),0;
	int n=ans>9?9:ans;
	printf("%.6lf",val[n]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Dangerous Syscalls

Test #1:

score: 0
Dangerous Syscalls

input:

1
2 3

output:


result:


Subtask #2:

score: 0
Dangerous Syscalls

Test #6:

score: 0
Dangerous Syscalls

input:

8
1 160005726539569
1 233
0 1
1 2947295521
1 686719856393
1 54289
1 12649337
1 37281334283719577

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Dangerous Syscalls

Test #57:

score: 0
Dangerous Syscalls

input:

15
15 17
2 3
5 31
4 5
12 29
38 41
3 11
44 47
16 23
11 19
6 13
3 37
1 2
21 43
5 7

output:


result:


Subtask #7:

score: 0
Skipped

Dependency #1:

0%