QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#262502#1835. Fancy FormulaswsyearAC ✓64ms3512kbC++141.3kb2023-11-23 19:59:302023-11-23 19:59:31

Judging History

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

  • [2023-11-23 19:59:31]
  • 评测
  • 测评结果:AC
  • 用时:64ms
  • 内存:3512kb
  • [2023-11-23 19:59:30]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ " = "), debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

using namespace std;

int mod;

int fpw(int a, int p = mod - 2) {
  int res = 1;
  while (p) {
    if (p & 1) res = 1ll * res * a % mod;
    a = 1ll * a * a % mod, p >>= 1;
  }
  return res;
}

void work() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if ((a + b) % mod != (c + d) % mod) return cout << "-1\n", void();
  int w = (a + b) % mod, inv = fpw(w);
  a = 1ll * a * inv % mod, c = 1ll * c * inv % mod;
  int ans = 0;
  while (true) {
    ll lim = (1ll << ans) - 1;
    if ((a - c + mod) % mod <= lim) return cout << ans << "\n", void();
    ans++, a = 2 * a % mod;
  }
}

int main() {
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  int t; cin >> mod >> t;
  while (t--) work();
}

详细

Test #1:

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

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: 26ms
memory: 3396kb

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: 30ms
memory: 3352kb

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: 0
Accepted
time: 64ms
memory: 3404kb

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:

29
26
28
-1
-1
27
30
30
30
26
27
-1
29
28
24
-1
30
27
21
-1
28
30
30
30
29
24
-1
30
28
29
-1
29
26
28
29
29
29
29
-1
28
29
29
-1
30
-1
27
26
28
26
30
27
29
30
30
-1
26
30
22
27
30
30
28
29
26
29
29
28
29
28
28
29
25
29
25
25
29
29
27
28
29
28
29
-1
27
-1
-1
27
25
30
-1
27
30
30
29
28
29
29
29
28
28
...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 58ms
memory: 3380kb

input:

999999323 100000
24495903 152638425 87217185 794250199
701443586 21540085 848139291 667628831
536695259 167429251 932417987 771705846
949269610 199487801 311910970 836846441
596115883 817268745 835693003 591405497
811816101 156369668 178128049 790057720
999725210 93460875 350432329 742753756
7750141...

output:

-1
-1
30
29
-1
30
27
30
28
25
30
29
29
30
-1
-1
27
28
-1
30
30
27
28
30
27
26
28
28
28
27
22
27
29
25
-1
-1
29
30
29
29
29
28
28
30
30
28
28
27
29
28
29
26
-1
30
28
27
30
30
-1
30
29
30
-1
29
29
30
29
29
29
26
29
29
30
30
30
30
27
29
30
-1
23
-1
28
27
-1
-1
30
-1
29
29
-1
-1
28
26
28
29
27
30
29
26
...

result:

ok 100000 numbers

Test #6:

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

input:

999999191 100000
920249851 263075456 910189304 273136003
259146706 440590130 217064118 394141081
606425484 261287223 359663798 711610714
633690165 59081357 129380510 563391012
703987751 364076553 981479539 86584765
767987403 851123667 887584320 731526750
634768660 684964613 976154077 343579196
63158...

output:

29
-1
-1
29
28
28
28
29
30
28
28
25
28
28
25
-1
-1
-1
26
28
30
30
30
-1
29
28
27
28
27
-1
-1
30
-1
30
26
30
-1
27
29
-1
-1
29
29
28
29
29
29
26
30
30
28
30
-1
26
28
29
28
26
27
27
-1
29
27
29
-1
23
29
30
25
26
27
27
30
30
30
-1
30
29
24
29
30
-1
28
29
29
29
28
30
24
26
30
30
29
28
27
29
28
28
29
29
...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 63ms
memory: 3336kb

input:

1000000007 100000
94813842 786719232 320409267 561123807
612512900 492834218 649856203 487862838
217068316 128383196 301099606 501864265
161142637 582561998 449556540 294148095
641324809 704256785 280041480 991884267
907600109 846641568 611011100 143230570
550215399 866959290 347513960 69660722
6856...

output:

28
-1
-1
27
-1
30
29
29
-1
30
26
29
29
28
29
-1
30
-1
28
26
28
25
28
29
27
27
27
-1
30
30
30
29
30
29
28
28
29
29
-1
28
29
29
29
-1
30
29
28
28
-1
25
28
30
27
28
30
30
-1
29
27
-1
29
29
27
28
28
25
-1
29
-1
30
28
27
29
29
27
29
24
29
29
29
29
-1
25
-1
28
-1
28
29
28
25
29
30
30
29
27
-1
30
30
-1
29
...

result:

ok 100000 numbers