QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#565650 | #1303. 斐波那契 | Elegia❄️ | 100 ✓ | 245ms | 17236kb | C++23 | 3.2kb | 2024-09-15 21:56:47 | 2024-10-09 15:20:13 |
Judging History
answer
/*
_/_/_/_/ _/_/_/_/_/ _/_/_/
_/ _/ _/ _/ _/
_/ _/ _/ _/ _/
_/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/
_/ _/ _/ _/ _/ _/_/
_/_/_/_/ _/_/ _/_/_/_/_/
_/_/_/_/ _/ _/ _/ _/
_/ _/ _/ _/ _/_/ _/_/
_/ _/ _/_/ _/ _/_/ _/
_/ _/ _/ _/ _/ _/
_/ _/ _/_/ _/ _/
_/ _/ _/ _/ _/ _/
_/_/_/_/ _/ _/ _/ _/
_/_/_/_/_/ _/_/_/_/_/ _/_/_/_/_/
_/ _/ _/
_/ _/ _/
_/ _/ _/_/_/_/
_/ _/ _/
_/ _/ _/
_/ _/_/_/_/_/ _/_/_/_/_/
_/_/_/_/_/ _/_/_/_/_/ _/_/_/_/_/
_/ _/ _/
_/ _/ _/
_/ _/ _/_/_/_/
_/ _/ _/
_/ _/ _/
_/ _/_/_/_/_/ _/_/_/_/_/
*/
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <iomanip>
#include <limits>
#include <numeric>
#define LOG(FMT...) fprintf(stderr, FMT)
using namespace std;
typedef unsigned long long ull;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void exGcd(int a, int b, int &x, int &y) {
if (!b) {
x = 1;
y = 0;
return;
}
exGcd(b, a % b, y, x);
y -= a / b * x;
}
int inv(int a, int mod) {
int x, y;
exGcd(a, mod, x, y);
return (x + mod) % mod;
}
const int N = 100010;
int a[N], b[N], ans[N];
int main() {
#ifdef ELEGIA
freopen("test.in", "r", stdin);
int nol_cl = clock();
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
map<int, vector<int>> qry;
for (int i = 1; i <= n; ++i) {
cin >> a[i] >> b[i];
if (a[i] && b[i]) {
int g = gcd(m, gcd(a[i], b[i]));
a[i] /= g;
b[i] /= g;
qry[m / g].push_back(i);
} else if (a[i] == 0) ans[i] = 0;
else if (b[i] == 0) ans[i] = 1;
}
for (auto [md, qs] : qry) {
vector<int> per = {0, 1};
int mod = md;
per.reserve(6 * mod);
while (true) {
int f = (per.back() + per[per.size() - 2]) % mod;
if (f == 0) break;
per.push_back(f);
}
map<pair<int, int>, int> mp;
auto significant = [&](int& x, int& y) {
int xx, yy;
exGcd(x, mod, xx, yy);
if (xx < 0) xx += mod;
int g = mod / gcd(x, mod);
x = x * (ull)xx % mod;
y = y * (ull)xx % g;
};
for (int i = 2; i != per.size(); ++i) {
int x = per[i - 1], y = per[i];
significant(x, y);
mp[make_pair(x, y)] = per.size() - i + 1;
}
for (int i : qs) {
significant(a[i], b[i]);
auto it = mp.find(make_pair(a[i], b[i]));
if (it == mp.end()) ans[i] = -1;
else ans[i] = it->second;
}
}
for (int i = 1; i <= n; ++i) cout << ans[i] << '\n';
#ifdef ELEGIA
LOG("Time: %dms\n", int ((clock()
-nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 1ms
memory: 3900kb
input:
969 953 283 22 14 309 296 278 686 299 600 76 808 942 914 842 832 412 172 905 81 603 115 900 709 870 203 110 413 682 476 109 59 773 932 661 635 191 692 557 246 787 619 265 708 127 477 644 870 893 392 301 942 908 60 23 0 388 520 642 869 239 269 125 60 570 491 650 337 303 391 918 377 916 174 129 778 49...
output:
-1 8 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 17 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 47 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...
result:
ok 969 numbers
Test #2:
score: 10
Accepted
time: 1ms
memory: 3668kb
input:
910 731 464 171 586 246 443 392 510 566 506 676 701 6 8 314 607 582 152 726 421 38 220 283 457 318 640 39 476 558 135 645 322 617 232 646 175 304 305 358 719 605 500 583 603 426 615 694 620 103 535 440 0 369 200 150 379 357 285 619 684 381 288 627 519 190 624 48 666 292 4 633 572 321 582 504 707 186...
output:
-1 98 170 315 296 276 170 -1 166 371 -1 -1 124 288 89 -1 37 -1 74 205 282 -1 56 -1 -1 0 274 127 -1 -1 313 -1 -1 80 116 -1 -1 373 -1 198 285 167 181 359 -1 -1 -1 -1 326 -1 227 127 -1 213 -1 -1 -1 -1 3 81 -1 268 -1 286 366 -1 270 314 -1 -1 -1 -1 -1 381 -1 -1 361 144 22 16 192 134 -1 -1 35 -1 187 45 14...
result:
ok 910 numbers
Test #3:
score: 10
Accepted
time: 63ms
memory: 7844kb
input:
93871 87133 34463 6856 84498 33902 46483 36855 2548 34168 64537 50633 49043 26878 57344 429 84531 50101 71032 55600 38963 23766 59075 19835 12397 81624 41154 58415 39586 39836 44721 17024 1461 66202 60445 42070 11480 50358 44751 63581 52923 72576 47597 65067 45696 53137 47331 63043 39086 62783 85082...
output:
-1 -1 -1 -1 6882 798 20658 26433 -1 43006 -1 -1 -1 30697 22272 18657 -1 -1 25579 30312 42690 3673 26394 41199 -1 -1 32245 3207 -1 -1 -1 -1 16219 -1 26246 -1 22530 -1 25089 -1 42618 32610 35226 -1 39535 -1 22939 17782 7001 6015 -1 -1 -1 2548 -1 21358 34910 29089 -1 31040 6655 32572 33929 -1 1108 -1 2...
result:
ok 93871 numbers
Test #4:
score: 10
Accepted
time: 57ms
memory: 7844kb
input:
94750 82837 75773 18293 55103 30435 28881 50086 1698 15822 36938 74666 60855 2162 18626 67201 53869 30085 21505 14938 48386 82762 7862 74898 12314 12084 25982 11146 45258 43835 61392 75785 70608 37335 37410 31830 25357 44338 58053 29057 14554 64141 30736 70571 56295 68896 74722 75617 56345 41813 559...
output:
5660 21397 -1 36330 -1 14852 -1 -1 27008 8302 29877 -1 35479 -1 32156 -1 -1 -1 -1 -1 -1 -1 -1 19271 37422 -1 -1 -1 17902 -1 -1 -1 -1 12390 11869 38194 -1 -1 5770 -1 -1 12088 23415 -1 -1 -1 -1 26309 -1 -1 31805 -1 -1 -1 -1 -1 -1 33448 41013 -1 -1 -1 38861 -1 32172 -1 38344 4318 -1 10470 14645 28198 -...
result:
ok 94750 numbers
Test #5:
score: 10
Accepted
time: 60ms
memory: 7492kb
input:
98826 63091 58627 56509 58453 33207 60944 49620 17900 26980 40343 47047 24828 28739 25234 17661 36154 20093 8248 24993 44591 47793 21092 62958 26204 23509 56499 35877 52841 54422 18061 29726 39410 30464 58656 30248 15501 22150 29724 36482 23531 13862 41941 31029 4244 11348 29708 20879 21829 31080 68...
output:
-1 24862 -1 26638 -1 -1 13737 -1 -1 9284 -1 -1 9255 32541 -1 196 9861 -1 9298 -1 -1 16332 -1 15241 -1 3008 21354 -1 31805 -1 -1 -1 10964 7597 11073 18747 -1 7153 -1 29231 25930 18356 3332 15248 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 17625 -1 -1 5432 30521 31476 -1 34731 1414 -1 -1 32341 -1 33836 5128 5...
result:
ok 98826 numbers
Test #6:
score: 10
Accepted
time: 66ms
memory: 7672kb
input:
94904 72317 42710 8125 62671 30616 34925 8668 66844 45649 18599 14193 4959 64618 4316 51257 53818 16448 58927 48953 5127 3894 17738 22827 49098 59014 18732 65585 35733 42854 2535 4065 36204 46153 69745 30298 60844 30597 46819 29398 57969 69152 2753 27603 33914 55280 34867 47757 37016 51169 32491 299...
output:
-1 28592 -1 22918 -1 23077 -1 34866 6902 34059 6239 8808 -1 -1 -1 19776 8972 6211 -1 -1 14343 -1 -1 22960 -1 22531 -1 18095 -1 -1 32338 38751 -1 -1 32341 -1 -1 -1 -1 37781 -1 37930 26904 -1 -1 39327 6892 -1 27328 -1 6411 5382 3956 -1 36408 -1 9837 -1 -1 -1 -1 13637 10686 24299 10449 -1 20412 -1 3248...
result:
ok 94904 numbers
Test #7:
score: 10
Accepted
time: 245ms
memory: 17236kb
input:
90340 93750 25077 80075 20576 27740 86004 67166 69747 35762 2894 40438 54541 84405 7607 27619 6944 87099 37825 83901 53800 30877 10634 19942 36858 63817 68293 31604 7939 30706 2998 12892 81531 43155 8805 34720 90248 22218 23280 54826 68166 16723 462 61571 16283 10029 1144 7572 16657 52984 32835 3704...
output:
88076 31831 28192 43864 19798 61661 66518 109989 173525 140175 -1 123552 -1 21667 43667 37511 23092 28829 45360 -1 -1 -1 -1 139003 848 9366 4827 69490 2270 -1 173802 107034 -1 175599 138520 3139 -1 87074 110269 146607 64228 158539 172191 -1 -1 50216 63044 47581 173311 7051 13613 -1 94974 173495 6231...
result:
ok 90340 numbers
Test #8:
score: 10
Accepted
time: 79ms
memory: 8264kb
input:
96931 65536 55412 32374 47450 33421 6908 53354 29289 9129 26519 23435 57277 9022 1789 28510 7494 29883 35449 31837 32202 47301 7274 32886 33635 4532 8387 50060 10236 51220 9611 58356 62936 48933 9053 45817 61451 47452 3561 24921 51967 60640 13426 64454 29936 59405 29262 46950 28272 17908 44906 3667 ...
output:
6927 -1 4113 2063 -1 -1 -1 -1 -1 -1 5510 -1 -1 -1 -1 5118 -1 -1 25163 3817 -1 26556 -1 -1 34503 -1 449 -1 -1 41149 30396 32922 -1 -1 22521 10289 -1 -1 -1 -1 -1 -1 8223 2063 9597 -1 -1 -1 20173 42315 34228 -1 -1 7476 32574 11576 41157 -1 -1 -1 -1 -1 -1 -1 45380 2836 -1 31905 47044 22040 -1 -1 19926 -...
result:
ok 96931 numbers
Test #9:
score: 10
Accepted
time: 118ms
memory: 10004kb
input:
94443 100000 82328 34403 89824 24111 30471 49907 21703 53495 38285 87602 50116 19021 17399 14054 86225 22003 56583 51529 77592 83931 17364 94726 12123 77005 31239 22400 10701 69218 73408 75851 52759 49483 91247 41361 85395 83467 35708 68879 43476 49593 64575 81685 27804 29599 90408 34889 3333 28189 ...
output:
10674 31872 -1 28931 4960 -1 7564 -1 -1 -1 2907 34196 1201 -1 74808 -1 -1 25145 -1 -1 -1 -1 -1 -1 -1 61178 -1 73138 10015 -1 16322 -1 1767 7158 -1 -1 -1 13003 28913 32673 -1 -1 -1 10294 -1 672 -1 1254 -1 71461 4873 32423 -1 9307 -1 30252 -1 -1 46483 -1 -1 -1 72724 -1 -1 2486 -1 -1 68449 -1 -1 30599 ...
result:
ok 94443 numbers
Test #10:
score: 10
Accepted
time: 29ms
memory: 5236kb
input:
91887 84480 42722 69562 40284 76507 13244 47864 33818 54658 47229 21878 13646 3378 45069 47239 34371 54031 73400 82625 61669 38082 77996 45694 52807 248 15487 50270 48414 13793 44454 55748 40003 48562 78591 67924 58165 65827 64328 55163 45716 24049 4005 20199 30375 35678 65566 75531 75736 53932 5942...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 587 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...
result:
ok 91887 numbers