QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#67483 | #2856. 数字表格 | alpha1022 | 100 ✓ | 500ms | 25360kb | C++23 | 1.6kb | 2022-12-10 16:25:02 | 2022-12-10 16:25:04 |
Judging History
answer
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 1e6;
const int mod = 1e9 + 7;
int t;
int cnt,prime[N + 5],vis[N + 5],mu[N + 5];
int f[N + 5],g[N + 5],prod[N + 5],inv[N + 5],ans;
int fpow(int a,int b)
{
int ret = 1;
for(;b;b >>= 1)
{
if(b & 1)
ret = (long long)ret * a % mod;
a = (long long)a * a % mod;
}
return ret;
}
int main()
{
f[1] = g[1] = mu[1] = prod[0] = inv[0] = prod[1] = inv[1] = 1;
for(register int i = 2;i <= N;++i)
{
prod[i] = 1,f[i] = (f[i - 1] + f[i - 2]) % mod,g[i] = fpow(f[i],mod - 2);
if(!vis[i])
prime[++cnt] = i,mu[i] = -1;
for(register int j = 1;j <= cnt && i * prime[j] <= N;++j)
{
vis[i * prime[j]] = 1;
if(!(i % prime[j]))
break;
mu[i * prime[j]] = -mu[i];
}
}
for(register int i = 1;i <= N;++i)
if(mu[i])
for(register int j = 1;i * j <= N;++j)
prod[i * j] = (long long)prod[i * j] * (mu[i] == 1 ? f[j] : g[j]) % mod;
for(register int i = 1;i <= N;++i)
prod[i] = (long long)prod[i] * prod[i - 1] % mod,inv[i] = fpow(prod[i],mod - 2);
scanf("%d",&t);
int n,m;
while(t--)
{
ans = 1;
scanf("%d%d",&n,&m);
if(n > m)
swap(n,m);
for(register int l = 1,r;l <= n;l = r + 1)
{
r = min(n / (n / l),m / (m / l));
ans = (long long)ans * fpow((long long)prod[r] * inv[l - 1] % mod,(long long)(n / l) * (m / l) % (mod - 1)) % mod;
}
printf("%d\n",ans);
}
}
詳細信息
Test #1:
score: 10
Accepted
time: 312ms
memory: 25264kb
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: 313ms
memory: 25356kb
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: 322ms
memory: 25312kb
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: 301ms
memory: 25300kb
input:
3 454940 562672 112643 767306 907862 417181
output:
695663156 628427697 686722724
result:
ok 3 lines
Test #5:
score: 10
Accepted
time: 305ms
memory: 25268kb
input:
3 745197 513056 269960 979569 208740 376976
output:
634928413 640591579 861814959
result:
ok 3 lines
Test #6:
score: 10
Accepted
time: 301ms
memory: 25356kb
input:
3 121356 462155 298930 200313 460606 503275
output:
748574275 576920 859930990
result:
ok 3 lines
Test #7:
score: 10
Accepted
time: 500ms
memory: 25260kb
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: 488ms
memory: 25360kb
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: 499ms
memory: 25340kb
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: 486ms
memory: 25300kb
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