QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#307836#8017. 计算cmk666100 ✓42ms45852kbC++238.8kb2024-01-19 10:38:522024-01-19 10:38:53

Judging History

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

  • [2024-01-19 10:38:53]
  • 评测
  • 测评结果:100
  • 用时:42ms
  • 内存:45852kb
  • [2024-01-19 10:38:52]
  • 提交

answer

/*
 * @Author:             cmk666
 * @Created time:       2024-01-19 10:12:16
 * @Last Modified time: 2024-01-19 10:37:13
 */
#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
#ifdef LOCAL
#include"debug.h"
#else
#define D(...) ((void)0)
#endif
using namespace std; using ll = long long;
#define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ )
#define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- )
namespace FastIO
{
// ------------------------------
// #define IN_HAS_NEG
// #define OUT_HAS_NEG
// #define CHK_EOF
// #define DISABLE_MMAP
// ------------------------------
#if __cplusplus < 201400
#error Please use C++14 or higher.
#endif
#if __cplusplus > 201700
#define INLINE_V inline
#else
#define INLINE_V
#endif
#if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifndef DISABLE_MMAP
#include<sys/mman.h>
#endif
#ifdef LOCAL
	inline char gc() { return getchar(); }
	inline void pc(char c) { putchar(c); }
#else
#ifdef DISABLE_MMAP
	INLINE_V constexpr int _READ_SIZE = 1 << 18;
	INLINE_V static char _read_buffer[_READ_SIZE], *_read_ptr = nullptr, *_read_ptr_end = nullptr;
	inline char gc()
	{
		if ( __builtin_expect(_read_ptr == _read_ptr_end, false) )
		{
			_read_ptr = _read_buffer;
			_read_ptr_end = _read_buffer + fread(_read_buffer, 1, _READ_SIZE, stdin);
#ifdef CHK_EOF
			if ( __builtin_expect(_read_ptr == _read_ptr_end, false) ) return EOF;
#endif
		}
		return *_read_ptr++;
	}
#else
	INLINE_V static const char *_read_ptr = (const char *)mmap(nullptr, INT_MAX, 1, 2, 0, 0);
	inline char gc() { return *_read_ptr++; }
#endif
	INLINE_V constexpr int _WRITE_SIZE = 1 << 18;
	INLINE_V static char _write_buffer[_WRITE_SIZE], *_write_ptr = _write_buffer;
	inline void pc(char c)
	{
		*_write_ptr++ = c;
		if ( __builtin_expect(_write_buffer + _WRITE_SIZE == _write_ptr, false) )
		{
			fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout);
			_write_ptr = _write_buffer;
		}
	}
	INLINE_V struct _auto_flush
	{
		inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); }
	}	_auto_flush;
#endif
#ifdef CHK_EOF
	inline constexpr bool _isdigit(char c) { return ( c & 16 ) && c != EOF; }
	inline constexpr bool _isgraph(char c) { return c > 32 && c != EOF; }
#else
	inline constexpr bool _isdigit(char c) { return c & 16; }
	inline constexpr bool _isgraph(char c) { return c > 32; }
#endif
	template < class T >
	INLINE_V constexpr bool _is_integer = numeric_limits < T >::is_integer;
	template < class T >
	INLINE_V constexpr bool _is_signed = numeric_limits < T >::is_signed;
	template < class T >
	INLINE_V constexpr bool _is_unsigned = _is_integer < T > && !_is_signed < T >;
	template <> INLINE_V constexpr bool _is_integer < __int128 > = true;
	template <> INLINE_V constexpr bool _is_integer < __uint128_t > = true;
	template <> INLINE_V constexpr bool _is_signed < __int128 > = true;
	template <> INLINE_V constexpr bool _is_unsigned < __uint128_t > = true;
#undef INLINE_V
	inline void read(char &c) { do c = gc(); while ( !_isgraph(c) ); }
	inline void read_cstr(char *s)
	{
		char c = gc(); while ( !_isgraph(c) ) c = gc();
		while ( _isgraph(c) ) *s++ = c, c = gc();
		*s = 0;
	}
	inline void read(string &s)
	{
		char c = gc(); s.clear(); while ( !_isgraph(c) ) c = gc();
		while ( _isgraph(c) ) s.push_back(c), c = gc();
	}
#ifdef IN_HAS_NEG
	template < class T, enable_if_t < _is_signed < T >, int > = 0 >
	inline void read(T &x)
	{
		char c = gc(); bool f = true; x = 0;
		while ( !_isdigit(c) ) { if ( c == 45 ) f = false; c = gc(); }
		if ( f ) while ( _isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc();
		else     while ( _isdigit(c) ) x = x * 10 - ( c & 15 ), c = gc();
	}
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 >
#else
	template < class T, enable_if_t < _is_integer < T >, int > = 0 >
#endif
	inline void read(T &x)
	{
		char c = gc(); while ( !_isdigit(c) ) c = gc();
		x = 0; while ( _isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc();
	}
	inline void write(char c) { pc(c); }
	inline void write_cstr(const char *s) { while ( *s ) pc(*s++); }
	inline void write(const string &s) { for ( char c : s ) pc(c); }
#ifdef OUT_HAS_NEG
	template < class T, enable_if_t < _is_signed < T >, int > = 0 >
	inline void write(T x)
	{
		char buffer[numeric_limits < T >::digits10 + 1]; int digits = 0;
		if ( x >= 0 )  do buffer[digits++] =  ( x % 10 ) | 48, x /= 10; while ( x );
		else { pc(45); do buffer[digits++] = -( x % 10 ) | 48, x /= 10; while ( x ); }
		while ( digits ) pc(buffer[--digits]);
	}
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 >
#else
	template < class T, enable_if_t < _is_integer < T >, int > = 0 >
#endif
	inline void write(T x)
	{
		char buffer[numeric_limits < T >::digits10 + 1]; int digits = 0;
		do buffer[digits++] = ( x % 10 ) | 48, x /= 10; while ( x );
		while ( digits ) pc(buffer[--digits]);
	}
	template < int N > struct _tuple_io_helper
	{
		template < class ...T >
		static inline void _read(tuple < T... > &x)
		{ _tuple_io_helper < N - 1 >::_read(x), read(get < N - 1 > (x)); }
		template < class ...T >
		static inline void _write(const tuple < T... > &x)
		{ _tuple_io_helper < N - 1 >::_write(x), pc(32), write(get < N - 1 > (x)); }
	};
	template <> struct _tuple_io_helper < 1 >
	{
		template < class ...T >
		static inline void _read(tuple < T... > &x) { read(get < 0 > (x)); }
		template < class ...T >
		static inline void _write(const tuple < T... > &x) { write(get < 0 > (x)); }
	};
	template < class ...T >
	inline void read(tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_read(x); }
	template < class ...T >
	inline void write(const tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_write(x); }
	template < class T1, class T2 >
	inline void read(pair < T1, T2 > &x) { read(x.first), read(x.second); }
	template < class T1, class T2 >
	inline void write(const pair < T1, T2 > &x) { write(x.first), pc(32), write(x.second); }
	template < class T1, class ...T2 >
	inline void read(T1 &x, T2 &...y) { read(x), read(y...); }
	template < class ...T >
	inline void read_cstr(char *x, T *...y) { read_cstr(x), read_cstr(y...); }
	template < class T1, class ...T2 >
	inline void write(const T1 &x, const T2 &...y) { write(x), write(y...); }
	template < class ...T >
	inline void write_cstr(const char *x, const T *...y) { write_cstr(x), write_cstr(y...); }
	template < class T >
	inline void print(const T &x) { write(x); }
	inline void print_cstr(const char *x) { write_cstr(x); }
	template < class T1, class ...T2 >
	inline void print(const T1 &x, const T2 &...y) { print(x), pc(32), print(y...); }
	template < class ...T >
	inline void print_cstr(const char *x, const T *...y) { print_cstr(x), pc(32), print_cstr(y...); }
	inline void println() { pc(10); }
	inline void println_cstr() { pc(10); }
	template < class ...T >
	inline void println(const T &...x) { print(x...), pc(10); }
	template < class ...T >
	inline void println_cstr(const T *...x) { print_cstr(x...), pc(10); }
}
using namespace FastIO;
constexpr int P = 998244353, N = 10000000;
inline int qpow(int x, int y)
{
	int z = 1;
	for ( ; y ; y >>= 1, x = (ll)x * x % P ) if ( y & 1 ) z = (ll)z * x % P;
	return z;
}
int pws[32768], pwb[32768], minp[10000009], p[670009], pl, n, m, ans;
int a_, b_, c_, d_; vector < pair < int, int > > w;
inline void init()
{
	*pws = *pwb = 1;
	For(i, 1, 32767) ( pws[i] = pws[i - 1] << 1 ) >= P && ( pws[i] -= P );
	( pwb[1] = pws[32767] << 1 ) >= P && ( pwb[1] -= P );
	For(i, 2, 32767) pwb[i] = (ll)pwb[i - 1] * pwb[1] % P;
	For(i, 2, N)
	{
		if ( !minp[i] ) p[++pl] = minp[i] = i;
		For(j, 1, pl)
		{
			if ( i * p[j] > N ) break;
			minp[i * p[j]] = p[j];
			if ( !( i % p[j] ) ) break;
		}
	}
	w.reserve(20);
}
inline int pw2(int x) { return (ll)pws[x & 32767] * pwb[x >> 15] % P; }
inline ll f(ll x, int a, int b)
{
	if ( !a || !b ) return 0;
	ll z = 1;
	for ( a = __gcd(a, b) ; a ; a >>= 1, x *= x ) if ( a & 1 ) z *= x;
	return z;
}
inline void dfs(int u, int d, int p)
{
	if ( !( d & 1 ) ) return;
	if ( u == (int)w.size() ) { ans = ( ans + (ll)p * pw2((ll)n * m / d % ( P - 1 )) ) % P; return; }
	dfs(u + 1, d, p), dfs(u + 1, d *= w[u].first, p *= ( w[u].first - 1 ));
	For(i, 2, w[u].second) dfs(u + 1, d *= w[u].first, p *= w[u].first);
}
inline void work()
{
	read(m, a_, b_, c_, d_), n = ( f(m, c_, d_) - f(m, a_, b_) ) / m % ( P - 1 ), w.clear();
	for ( int x = m, y ; x != 1 ; )
	{
		y = minp[x], x /= y, w.emplace_back(y, 1);
		while ( !( x % y ) ) x /= y, w.back().second++;
	}
	ans = 0, dfs(0, 1, 1), println((ll)ans * qpow(m, P - 2) % P);
}
int main() { int t; init(), read(t); For(tt, 1, t) work(); return 0; }
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 5
Accepted
time: 39ms
memory: 45444kb

input:

1
2 0 0 1 1

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 5
Accepted
time: 38ms
memory: 45840kb

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:

731703617
36583482
921758136
200585229
775628782
918519135
843112918
189633378
490053994
978650670
950509833
676056009
779036669
440843710
100336162
346004888
932593641
884032378
711656920
947980296
426567216
323561369
509408552
179961669
729357055
684325623
737411410
914193717
568399251
804543195
8...

result:

ok 10000 numbers

Test #3:

score: 5
Accepted
time: 39ms
memory: 45832kb

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:

255347738
647570858
305733932
883401245
147308187
159117024
729058082
139049435
804375441
994579501
600632128
232637115
941190500
715981463
326844764
102500398
808296443
716252001
232991119
473122601
268629101
318492550
119201215
465578518
536636991
325784467
942591036
606686968
163626491
161188224
...

result:

ok 10000 numbers

Test #4:

score: 5
Accepted
time: 42ms
memory: 45852kb

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:

556751174
199156261
382190642
647699394
78956219
955030901
313591644
369578586
542007033
718615934
532890749
962931672
484395929
942407729
302321584
530343965
655984434
481039470
621185747
826179506
795259277
397846910
549242810
136309187
253325940
944268190
517220798
758931541
362336723
574593619
9...

result:

ok 10000 numbers

Test #5:

score: 5
Accepted
time: 35ms
memory: 45644kb

input:

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

output:

1
2
1024
6710912

result:

ok 4 number(s): "1 2 1024 6710912"

Test #6:

score: 5
Accepted
time: 37ms
memory: 45616kb

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:

8581218
487933114
8581218
919504178
296665006

result:

ok 5 number(s): "8581218 487933114 8581218 919504178 296665006"

Test #7:

score: 5
Accepted
time: 40ms
memory: 45524kb

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:

336307822
997249957
706112470
706112470
856358531

result:

ok 5 number(s): "336307822 997249957 706112470 706112470 856358531"

Test #8:

score: 5
Accepted
time: 30ms
memory: 45520kb

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:

336848941
997249957
706112470
706112470
811628181

result:

ok 5 number(s): "336848941 997249957 706112470 706112470 811628181"

Test #9:

score: 5
Accepted
time: 36ms
memory: 45576kb

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:

336307822
336307822
488237375
811628181
306984283

result:

ok 5 number(s): "336307822 336307822 488237375 811628181 306984283"

Test #10:

score: 5
Accepted
time: 41ms
memory: 45472kb

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:

413751362
582959663
739853128
394067700
460843296

result:

ok 5 number(s): "413751362 582959663 739853128 394067700 460843296"

Test #11:

score: 5
Accepted
time: 36ms
memory: 45580kb

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:

329246322
961491285
986208581
755475251
582959663

result:

ok 5 number(s): "329246322 961491285 986208581 755475251 582959663"

Test #12:

score: 5
Accepted
time: 32ms
memory: 45508kb

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:

8
4
2
4
4

result:

ok 5 number(s): "8 4 2 4 4"

Test #13:

score: 5
Accepted
time: 31ms
memory: 45524kb

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:

825344814
187842409
805026391
353977868
659754483

result:

ok 5 number(s): "825344814 187842409 805026391 353977868 659754483"

Test #14:

score: 5
Accepted
time: 38ms
memory: 45584kb

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:

733422553
544857646
790296076
147846588
746361195

result:

ok 5 number(s): "733422553 544857646 790296076 147846588 746361195"

Test #15:

score: 5
Accepted
time: 37ms
memory: 45588kb

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:

919146531
401833612
450887104
293028836
782651767

result:

ok 5 number(s): "919146531 401833612 450887104 293028836 782651767"

Test #16:

score: 5
Accepted
time: 38ms
memory: 45588kb

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:

396457042
7239581
141714492
897734272
587745788

result:

ok 5 number(s): "396457042 7239581 141714492 897734272 587745788"

Test #17:

score: 5
Accepted
time: 42ms
memory: 45516kb

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:

263714877
43312442
266698135
743766563
112072777

result:

ok 5 number(s): "263714877 43312442 266698135 743766563 112072777"

Test #18:

score: 5
Accepted
time: 30ms
memory: 45440kb

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:

625186250
867386840
189461622
776993424
454494624

result:

ok 5 number(s): "625186250 867386840 189461622 776993424 454494624"

Test #19:

score: 5
Accepted
time: 40ms
memory: 45472kb

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:

962318822
591855057
657246420
608891613
558044615

result:

ok 5 number(s): "962318822 591855057 657246420 608891613 558044615"

Test #20:

score: 5
Accepted
time: 37ms
memory: 45576kb

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:

896071730
900065313
663315460
701166665
386862478

result:

ok 5 number(s): "896071730 900065313 663315460 701166665 386862478"