QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#563152 | #2856. 数字表格 | Elegia | 100 ✓ | 641ms | 16288kb | C++23 | 1.8kb | 2024-09-14 03:08:46 | 2024-09-14 03:08:48 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1000010, P = 1e9L + 7, PC = 500010;
int pc;
int mu[N], fib[N], prod[N];
int p[PC];
bool f[N];
void pre();
void sieve();
int rev(int x);
int mpow(int x, ll k);
void ex_gcd(int a, int b, int& x, int& y);
int main() {
int t, n, m, ans;
pre();
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
if (n > m)
swap(n, m);
ans = 1;
for (int l = 1, r; l <= n; l = r + 1) {
r = min(n / (n / l), m / (m / l));
ans = (ll)ans * mpow((ll)prod[r] * rev(prod[l - 1]) % P, (ll)(n / l) * (m / l)) % P;
}
printf("%d\n", ans);
}
return 0;
}
int mpow(int x, ll k) {
int ret = 1;
for (; k; k >>= 1) {
if (k & 1)
ret = (ll)ret * x % P;
x = (ll)x * x % P;
}
return ret;
}
void ex_gcd(int a, int b, int& x, int& y) {
if (b == 0) {
x = 1;
y = 0;
return;
}
ex_gcd(b, a % b, y, x);
y -= a / b * x;
}
int rev(int a) {
int x, y;
ex_gcd(a, P, x, y);
if (x < 0)
x += P;
return x;
}
void sieve() {
mu[1] = 1;
for (int i = 2; i < N; ++i) {
if (!f[i]) {
p[++pc] = i;
mu[i] = -1;
}
for (int j = 1; (ll)i * p[j] < N; ++j) {
f[i * p[j]] = true;
mu[i * p[j]] = -mu[i];
if (i % p[j] == 0) {
mu[i * p[j]] = 0;
break;
}
}
}
}
void pre() {
sieve();
fib[1] = 1;
for (int i = 2; i < N; ++i) {
fib[i] = fib[i - 1] + fib[i - 2];
if (fib[i] >= P)
fib[i] -= P;
}
fill(prod, prod + N, 1);
for (int i = 1; i < N; ++i)
for (int j = 1; i * j < N; ++j)
switch (mu[j]) {
case 1:
prod[i * j] = (ll)prod[i * j] * fib[i] % P;
break;
case -1:
prod[i * j] = (ll)prod[i * j] * rev(fib[i]) % P;
break;
}
for (int i = 2; i < N; ++i)
prod[i] = (ll)prod[i] * prod[i - 1] % P;
}
详细
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 297ms
memory: 16276kb
input:
1000 82 5 85 13 18 82 39 47 85 97 28 33 72 40 38 43 76 44 9 45 57 96 3 54 60 20 43 30 45 46 11 53 14 84 50 90 10 39 39 20 70 50 95 13 36 54 47 82 47 52 68 44 36 53 13 94 100 69 56 80 16 28 93 10 52 39 66 75 68 17 37 74 66 64 5 69 34 84 74 21 44 67 36 3 26 55 20 54 43 50 67 14 49 54 13 11 4 59 83 72 ...
output:
697857603 513287135 493843565 685803126 740209982 40610353 396156831 744451085 76570868 570036963 171027959 262144 893084879 939049770 926146193 722919138 964641357 942426458 622528402 451760491 14237564 225318722 518777888 449825043 341812093 432079000 772254207 169012750 411792446 748968062 756385...
result:
ok 1000 lines
Test #2:
score: 10
Accepted
time: 309ms
memory: 16188kb
input:
1000 456 760 791 350 655 528 2 279 69 639 512 306 308 162 717 572 992 483 222 419 425 368 391 134 541 346 150 960 852 350 270 993 338 455 197 621 281 194 446 443 157 488 776 127 54 512 902 953 321 874 397 451 655 813 305 303 372 210 655 671 689 895 332 867 219 734 189 279 490 563 45 794 43 1 907 328...
output:
384572586 128416505 177153016 1 792110166 378466851 634682075 140555279 785606784 224545347 480461357 787221913 152690988 276697635 873944871 15937156 787784125 74845458 378183569 770058883 553415281 664773218 54099655 4520332 136745043 642040144 647801092 694272606 411423640 772548747 991414475 262...
result:
ok 1000 lines
Test #3:
score: 10
Accepted
time: 307ms
memory: 15728kb
input:
1000 834 24 939 905 741 833 728 412 665 30 90 620 517 891 130 313 639 707 544 959 223 611 85 709 250 300 322 983 393 173 407 404 831 110 165 881 991 422 885 165 819 590 815 411 926 844 220 395 363 553 555 993 435 636 704 644 900 365 424 960 149 578 894 636 986 805 554 661 798 699 77 762 172 751 166 ...
output:
644802145 232279121 379400155 444492502 954058278 813885568 18387337 502115986 340496387 84878668 494148625 561893309 729783825 495024707 306032686 744614950 310694222 151470960 67195602 891797129 572646117 912571586 762567644 631897452 923582319 898125642 924489975 992290630 669842153 864854675 343...
result:
ok 1000 lines
Test #4:
score: 10
Accepted
time: 294ms
memory: 16180kb
input:
3 454940 562672 112643 767306 907862 417181
output:
695663156 628427697 686722724
result:
ok 3 lines
Test #5:
score: 10
Accepted
time: 302ms
memory: 16288kb
input:
3 745197 513056 269960 979569 208740 376976
output:
634928413 640591579 861814959
result:
ok 3 lines
Test #6:
score: 10
Accepted
time: 297ms
memory: 16260kb
input:
3 121356 462155 298930 200313 460606 503275
output:
748574275 576920 859930990
result:
ok 3 lines
Test #7:
score: 10
Accepted
time: 636ms
memory: 16144kb
input:
1000 283558 168544 143615 807608 461779 307243 759795 341819 791247 562279 899971 582242 112436 804931 512924 539518 506466 351699 256430 581061 65275 126030 432494 604369 369382 716240 614292 212703 246925 304537 770781 488081 760542 135820 242826 868717 832206 664944 689055 660507 477009 178162 25...
output:
283014868 990243232 388248159 616196065 219886182 309382041 448679213 534956539 918843207 55781398 824669761 474166751 307997809 151932376 500358371 591586078 682389632 341823993 554507625 688852617 634347229 172864935 122553460 202758604 858950400 301189134 1594673 617393878 170625580 610595922 172...
result:
ok 1000 lines
Test #8:
score: 10
Accepted
time: 636ms
memory: 16176kb
input:
1000 440274 901599 691601 797856 838055 495802 684464 663111 25477 958082 634124 986486 784532 84086 595489 737743 803588 746107 507375 445527 429256 581591 105532 192505 129686 524151 510160 547137 9897 903082 906231 195234 529919 163684 992899 24432 718107 697468 300039 232039 619908 616814 437725...
output:
365320913 681614706 847286353 671477779 264121697 585088898 368905317 11027303 889121172 109652792 80510572 642059979 480108117 599586524 900360019 164051816 395310915 906701911 787811872 790784785 818963886 763793845 335411670 167129596 14877864 617021327 830035095 90699668 633416819 100892835 2193...
result:
ok 1000 lines
Test #9:
score: 10
Accepted
time: 641ms
memory: 16232kb
input:
1000 82099 145723 916973 256099 847467 5679 827410 634711 814947 648717 452883 705336 279959 643364 526334 114296 171651 647528 93859 297708 405036 664496 286039 691597 194839 977656 79922 965177 949648 362655 190289 994355 414692 338602 373526 895198 362151 16511 279011 797510 181551 695915 901667 ...
output:
892557352 602766132 609986864 451863890 987591917 727546364 493768397 360043516 725932491 358432557 924555808 537966114 376147353 644329506 82216168 421049387 709247573 201697130 818623765 165832955 251779127 289533274 127590777 387082723 933248973 862380388 298729759 964486678 532229940 144255370 9...
result:
ok 1000 lines
Test #10:
score: 10
Accepted
time: 630ms
memory: 16196kb
input:
1000 289425 176253 54044 388424 551782 18069 271647 334132 2932 750739 280736 422385 118021 716182 675003 529602 507815 849891 921488 524106 871151 656480 728325 392405 388722 388186 661186 781712 111306 853376 921908 442700 128791 264037 219787 338943 816123 586242 51579 729859 671516 827378 823742...
output:
941313418 330479975 400191059 317961212 608283349 768465305 270252947 548702642 348199404 783788857 325184947 319667541 309227985 601658259 556002932 783792811 164680409 830772331 781714629 345353453 68627791 609976729 790036886 838208236 772779707 712165773 786518563 5069623 916902879 262508186 809...
result:
ok 1000 lines