QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#810455#7230. Fraction FactoryAuroreWA 1ms5724kbC++231.4kb2024-12-11 22:48:092024-12-11 22:48:11

Judging History

This is the latest submission verdict.

  • [2024-12-11 22:48:11]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 5724kb
  • [2024-12-11 22:48:09]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
#define pr(x,y) make_pair(x,y)
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int buf[105];
inline void print(int x,char ch=' '){
	if(x<0) putchar('-'),x=-x;
	int tot=0;
	do{
		buf[++tot]=x%10;
		x/=10;
	}while(x);
	for(int i=tot;i;i--) putchar(buf[i]+'0');
	putchar(ch);
}
const int MAXN=1e6+5;
int exgcd(int a,int b,int &x,int &y){
	if(!b){
		x=1,y=0;
		return a;
	}
	int ans,p,q;
	ans=exgcd(b,a%b,p,q);
	x=q;
	y=p-a/b*q;
	return ans;
}
int inv(int a,int b){
	int x,y;
	exgcd(a,b,x,y);
	return (x%b+b)%b;
}
int gcd(int a,int b){
	while(b){
		a=a%b;
		swap(a,b);
	}
	return a;
}
int n,m,a[MAXN],b[MAXN];

signed main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<=m;i++){
		b[i]=read();
		for(int j=1;j<=n;j++){
			int d=gcd(a[j],b[i]);
			a[j]/=d,b[i]/=d;
		}
	}
	
	int T=read();
	while(T--){
		int mod=read();
		int A=1,B=1;
		for(int i=1;i<=n;i++) A=A*a[i]%mod;
		
		bool flag=1;
		for(int i=1;i<=m;i++)
			if(gcd(b[i],mod)!=1) flag=0;
		if(!flag){
			cout<<"DIVISION BY ZERO\n";
		}
		else{
			for(int i=1;i<=m;i++) B=B*b[i]%mod;
			B=inv(B,mod);
			print(A*B%mod,'\n');
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5708kb

input:

3 2
8 11 14
9 12
4
8
9
10
11

output:

4
DIVISION BY ZERO
4
0

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 5724kb

input:

2 2
1 2
4 3
10
5
7
11
13
17
19
23
29
31
37

output:

1
6
2
11
3
16
4
5
26
31

result:

ok 10 lines

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5624kb

input:

4 6
111111111111111111 1000000000000000000 1000000000000000 135792468013579246
10000000000000000 100000000000000 999999999999999999 123456789123456789 239239239932932932 1357924680
10
1161978962132362
539566136338457734
758923339452654441
655309120486827715
84306884606421160
911731869459297905
82243...

output:

DIVISION BY ZERO
DIVISION BY ZERO
DIVISION BY ZERO
645128586128606609
DIVISION BY ZERO
-393309178199638682
DIVISION BY ZERO
DIVISION BY ZERO
DIVISION BY ZERO
DIVISION BY ZERO

result:

wrong answer 4th lines differ - expected: '5719954405760135', found: '645128586128606609'