QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397111#8017. 计算zqs5 145ms172848kbC++141.8kb2024-04-23 16:48:052024-04-23 16:48:05

Judging History

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

  • [2024-04-23 16:48:05]
  • 评测
  • 测评结果:5
  • 用时:145ms
  • 内存:172848kb
  • [2024-04-23 16:48:05]
  • 提交

answer

#include <cstdio>
#define int long long

const int mod = 998244353;
inline int qpow(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1) res = 1ll * res * a % mod;
        a = 1ll * a * a % mod, b >>= 1;
    }
    return res;
}
bool mark[10000005];
int pri[1000005], phi[10000005], pow2[10000005], facs[100005], cnt;
void init(int n) {
    phi[1] = 1;
    for (int i = 2; i <= n; ++ i) {
        if (!mark[i]) phi[i] = i - 1, pri[++ cnt] = i;
        for (int j = 1; j <= cnt && i * pri[j] <= n; ++ j) {
            mark[i * pri[j]] = true;
            if (i % pri[j] == 0) {phi[i * pri[j]] = phi[i] * pri[j]; break;}
            phi[i * pri[j]] = phi[i] * (pri[j] - 1);
        }
}
    }
int gcd(int n, int m) {return m ? gcd(m, n % m) : n;}
int F(int m, int a, int b) {
    if (!a || !b) return 0;
    int g = gcd(a, b), s = 1;
    while (g --) s *= m;
    return s + 1;
}

signed main() {
    init(10000000);
    pow2[0] = 1;
    for (int i = 1; i <= 10000000; ++ i) pow2[i] = 2ll * pow2[i - 1] % mod;
    int _; scanf("%lld", &_);
    while (_ --) {
        int m, A, B, C, D; scanf("%lld%lld%lld%lld%lld", &m, &A, &B, &C, &D);
        int n = (F(m, C, D) - F(m, A, B)) / m, ans = 0, len = 2;
        facs[1] = 1, facs[2] = m;
        for (int i = 1; pri[i] * pri[i] <= m && pri[i] < m; ++ i) if (m % pri[i] == 0) {
            facs[++ len] = pri[i];
            if (pri[i] * pri[i] != m) facs[++ len] = m / pri[i];
        }
        for (int i = 1; i <= len; ++ i) {
            int g = facs[i];
            if ((m / g) & 1)
                ans = (ans + 1ll * phi[m / g] * qpow(2, n % (mod - 1) * g % (mod - 1))) % mod;
        }
        ans = 1ll * ans * qpow(m, mod - 2) % mod;
        printf("%lld", ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 115ms
memory: 172692kb

input:

1
2 0 0 1 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Wrong Answer
time: 143ms
memory: 172820kb

input:

10000
9026580 948 269 622 88
9346507 381 242 826 606
9266080 948 589 28 666
8566088 808 523 402 338
9832014 278 123 146 1000
8000150 613 878 146 740
8296526 404 147 608 398
9062880 494 203 336 382
9375271 823 736 54 676
8465119 505 414 874 772
9535971 784 983 426 802
8258325 817 977 172 862
9656017 ...

output:

408149662365834821533352824456884309308299311107366014505266573342897014900539945818487786713546381002978094566458674480448965595837967967312789009263348149133697301389655391150109527027780352430600538061799616697293570559794912405490117375844214375683992518045431952185044722104081326654479355616761...

result:

wrong output format Expected integer, but "408149662365834821533352824456...7396702880368980848574756882643" found

Test #3:

score: 0
Wrong Answer
time: 145ms
memory: 172808kb

input:

10000
9060194 192 71 24 178
8861291 135 338 24 794
8800613 173 760 704 362
9878509 367 418 58 964
8183946 856 951 406 316
8087229 458 105 770 342
8269502 205 147 614 334
8877019 851 143 206 10
9044859 710 949 210 584
8887395 571 856 550 428
8208494 383 628 74 646
9949585 697 450 794 738
9938335 224 ...

output:

345274872647570858305733932883401245790514791753662223302085137139049435731832418931818790750947882605768038681143071598146344307948144171408657549408280539008629533586141578305268629101318492550307944890566394229599549796635899234406978150606686968138935924373973519866891560873586363798425975929814...

result:

wrong output format Expected integer, but "345274872647570858305733932883...5220448848382608211559843723149" found

Test #4:

score: 0
Wrong Answer
time: 130ms
memory: 172752kb

input:

10000
9110615 854 153 494 298
9386442 749 922 386 696
9270958 160 53 630 562
9643022 573 997 226 836
9824638 357 16 34 332
9962202 439 312 40 854
8974913 815 436 710 876
9362731 411 272 998 760
9814831 220 961 962 274
9310979 19 890 782 588
9425378 897 14 212 870
9572172 430 419 334 166
9101141 565 ...

output:

556751174463166750498677033281292381443857078783887783135916441964163719886221137186159345174069506807518905133189894240772916208102938909061037580076121133841840162323361992533679525927779663612827744210818704442911590522944268190599054721376874051177285514325512535577021097284616488645738516797192...

result:

wrong output format Expected integer, but "556751174463166750498677033281...9270531897822551422842399381343" found

Test #5:

score: 0
Wrong Answer
time: 96ms
memory: 172848kb

input:

4
3 4 5 6 1
2 6 1 8 10
4 1 4 2 2
5 0 10 2 10

output:

1210246710912

result:

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

Test #6:

score: 0
Wrong Answer
time: 111ms
memory: 172848kb

input:

5
18 10 9 4 6
14 7 4 4 6
18 6 5 8 2
12 5 2 4 10
11 5 6 2 6

output:

85812184879331148581218919504178296665006

result:

wrong output format Expected integer, but "85812184879331148581218919504178296665006" found

Test #7:

score: 0
Wrong Answer
time: 106ms
memory: 172748kb

input:

5
11 9 5 3 3
12 8 9 9 6
10 10 7 3 9
10 5 4 3 6
6 9 6 4 8

output:

336307822997249957706112470706112470856358531

result:

wrong output format Expected integer, but "336307822997249957706112470706112470856358531" found

Test #8:

score: 0
Wrong Answer
time: 125ms
memory: 172844kb

input:

5
4 5 6 5 10
12 8 5 9 3
10 4 9 9 3
10 5 6 6 3
6 5 7 4 8

output:

336848941997249957706112470706112470811628181

result:

wrong output format Expected integer, but "336848941997249957706112470706112470811628181" found

Test #9:

score: 0
Wrong Answer
time: 106ms
memory: 172800kb

input:

5
11 80 29 27 84
11 31 27 87 6
4 46 54 95 80
6 45 62 88 92
12 70 34 3 75

output:

336307822336307822488237375811628181306984283

result:

wrong output format Expected integer, but "336307822336307822488237375811628181306984283" found

Test #10:

score: 0
Wrong Answer
time: 119ms
memory: 172800kb

input:

5
58 91 37 75 5
62 99 67 10 75
55 51 92 70 85
55 86 16 50 85
29 54 95 36 78

output:

413751362582959663739853128394067700460843296

result:

wrong output format Expected integer, but "413751362582959663739853128394067700460843296" found

Test #11:

score: 0
Wrong Answer
time: 106ms
memory: 172812kb

input:

5
10 57 94 99 18
19 97 77 63 98
62 44 4 90 35
61 3 54 25 60
62 57 65 95 70

output:

329246322961491285986208581755475251582959663

result:

wrong output format Expected integer, but "329246322961491285986208581755475251582959663" found

Test #12:

score: 0
Wrong Answer
time: 135ms
memory: 172824kb

input:

5
5 0 0 9 5
4 0 0 1 5
2 0 0 7 5
3 0 0 3 7
3 0 0 9 5

output:

84244

result:

wrong answer 1st numbers differ - expected: '8', found: '84244'

Test #13:

score: 0
Wrong Answer
time: 105ms
memory: 172744kb

input:

5
1931 633 387 65 265
1334 942 887 115 455
1547 511 57 65 920
1815 983 313 575 430
1497 749 773 25 740

output:

825344814187842409805026391713969337659754483

result:

wrong output format Expected integer, but "825344814187842409805026391713969337659754483" found

Test #14:

score: 0
Wrong Answer
time: 118ms
memory: 172792kb

input:

5
1676 347 892 10 545
1552 901 243 595 705
1585 181 32 900 215
1043 147 153 250 195
1343 519 863 610 345

output:

394998588400924401790296076147846588746361195

result:

wrong output format Expected integer, but "394998588400924401790296076147846588746361195" found

Test #15:

score: 0
Wrong Answer
time: 110ms
memory: 172848kb

input:

5
1507 98 480 995 565
1130 476 464 710 925
1556 518 459 65 445
1153 277 530 485 860
1329 191 777 315 905

output:

919146531406192444194144309293028836782651767

result:

wrong output format Expected integer, but "919146531406192444194144309293028836782651767" found

Test #16:

score: 0
Wrong Answer
time: 129ms
memory: 172844kb

input:

5
1260 985 161 855 395
1919 286 557 10 155
1439 586 749 915 730
1297 750 832 245 855
1693 134 289 355 200

output:

8659749277239581141714492897734272587745788

result:

wrong output format Expected integer, but "8659749277239581141714492897734272587745788" found

Test #17:

score: 0
Wrong Answer
time: 104ms
memory: 172824kb

input:

5
95803 976 729 633 237
99669 606 7 489 816
80026 339 914 753 933
97238 844 430 666 537
70169 394 204 411 738

output:

26371487743312442266698135743766563112072777

result:

wrong output format Expected integer, but "26371487743312442266698135743766563112072777" found

Test #18:

score: 0
Wrong Answer
time: 108ms
memory: 172800kb

input:

5
86711 965 851 300 273
97658 466 416 633 603
89583 407 591 411 3
84126 987 514 822 837
79996 9 166 807 15

output:

62518625087998346290804716261667146111726485

result:

wrong output format Expected integer, but "62518625087998346290804716261667146111726485" found

Test #19:

score: 0
Wrong Answer
time: 119ms
memory: 172760kb

input:

5
90325 2 48 195 528
83446 123 809 897 60
92466 526 768 441 447
95582 319 251 843 447
95424 374 218 162 597

output:

791697605203097311365118887608891613238642105

result:

wrong output format Expected integer, but "791697605203097311365118887608891613238642105" found

Test #20:

score: 0
Wrong Answer
time: 111ms
memory: 172796kb

input:

5
80746 952 565 615 192
71949 878 950 357 789
99398 301 646 942 699
94853 670 947 141 276
82409 554 873 375 213

output:

31923427820041007318998750701166665386862478

result:

wrong output format Expected integer, but "31923427820041007318998750701166665386862478" found