QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#36069#1835. Fancy FormulasFroggyguaWA 96ms3704kbC++17748b2022-06-23 21:24:432022-06-23 21:24:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-23 21:24:46]
  • 评测
  • 测评结果:WA
  • 用时:96ms
  • 内存:3704kb
  • [2022-06-23 21:24:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int mod,Q;
int qpow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;
		b>>=1;
	}
	return ans;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>mod>>Q;
	while(Q--){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		if((a+b)%mod!=(c+d)%mod){
			cout<<-1<<'\n';
			continue;
		}
		if(a==c){
			cout<<0<<'\n';
			continue;
		}
		int s=(a+b)%mod;
		int invs=qpow(s,mod-2);
		a=1LL*a*invs%mod,c=1LL*c*invs%mod;
		for(int o=1,l=a,r=a,len=1;;++o){
			len<<=1;
			l=(2*l-1+mod)%mod;
			r=2*r%mod;
			if(len>=mod||(l<=r&&c>=l&&c<=r)||(l>r&&(c<=r||c>=l))){
				cout<<o<<'\n';
				break;
			}
		}
	}
	return 0;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3704kb

input:

5 10
2 1 3 0
2 1 4 4
1 3 4 0
0 2 0 4
3 3 1 2
0 1 0 1
0 3 0 3
0 1 0 1
1 2 4 4
1 0 1 1

output:

2
1
2
-1
-1
0
0
0
1
-1

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 48ms
memory: 3672kb

input:

97 100000
30 56 74 12
95 39 8 29
11 42 76 74
48 63 58 53
74 22 85 11
80 23 84 4
30 90 30 90
92 91 41 45
21 82 11 92
65 30 28 67
74 57 95 36
16 31 78 66
2 77 6 73
83 20 41 62
45 44 92 94
96 28 77 47
76 12 87 1
47 80 42 85
46 91 65 72
23 39 4 58
21 96 37 80
83 33 66 50
84 21 61 44
4 78 47 35
39 50 39 ...

output:

6
6
5
6
6
-1
0
4
6
7
7
6
6
2
7
7
6
7
6
4
6
5
5
3
0
4
5
6
6
5
5
5
6
5
5
6
7
-1
5
4
-1
6
4
-1
4
6
5
5
-1
6
6
7
0
-1
2
-1
5
-1
5
7
2
4
6
4
6
6
-1
6
7
6
6
7
6
-1
4
2
7
0
6
-1
6
2
-1
4
6
5
-1
7
3
5
0
-1
7
3
4
6
4
6
0
1
5
7
6
-1
-1
-1
6
5
5
5
3
3
3
-1
-1
2
3
5
6
-1
-1
7
-1
5
7
6
5
6
-1
3
5
5
-1
4
5
6
-1
6...

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 64ms
memory: 3588kb

input:

1217 100000
1084 896 1095 885
1106 523 400 12
1200 37 911 326
992 1098 706 167
917 274 409 782
1154 689 530 96
738 563 879 422
389 1077 1034 432
415 735 61 1089
101 114 388 1044
512 255 818 1166
1149 620 663 1106
655 636 1036 255
86 922 154 854
848 990 740 1098
347 693 534 1192
521 126 866 68
235 36...

output:

9
8
9
7
10
11
8
9
8
9
10
9
10
9
10
-1
-1
10
8
10
10
8
11
10
10
7
-1
7
5
10
-1
9
10
9
8
9
6
10
-1
-1
10
8
9
10
7
9
-1
11
10
8
8
11
-1
-1
8
9
10
11
-1
9
-1
9
8
10
9
10
10
10
6
9
-1
10
10
10
6
10
10
9
10
9
-1
9
6
4
8
9
6
8
10
8
10
10
10
-1
10
10
9
-1
10
11
10
9
8
8
10
9
8
5
7
10
10
9
8
8
8
8
11
11
6
8
...

result:

ok 100000 numbers

Test #4:

score: -100
Wrong Answer
time: 96ms
memory: 3444kb

input:

999999001 100000
283613712 224836068 452066136 56383644
830489448 158022048 357330405 631181091
920630113 770772345 401855596 289547861
264134671 92704742 146681100 226345536
879982866 896474292 569906689 421772490
229953446 13241605 620830189 622363863
704084273 156005177 727710355 132379095
352992...

output:

4
2
1
-1
-1
1
2
13
1
3
7
-1
3
5
4
-1
7
1
8
-1
7
1
1
1
7
6
-1
8
2
3
-1
7
4
5
1
1
1
7
-1
4
10
2
-1
5
-1
12
1
3
3
1
3
9
1
7
-1
4
1
5
1
4
1
3
6
1
2
14
1
2
3
1
3
1
10
3
11
2
3
4
2
1
1
1
-1
11
-1
-1
1
4
5
-1
1
2
6
6
5
2
2
3
7
6
12
2
-1
5
1
6
3
6
2
1
5
-1
5
4
-1
-1
1
-1
5
-1
9
5
1
3
4
10
4
5
3
1
-1
7
5
5
1...

result:

wrong answer 1st numbers differ - expected: '29', found: '4'