QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#611737#9309. GraphwjcAC ✓354ms13416kbC++142.4kb2024-10-04 22:27:332024-10-04 22:27:39

Judging History

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

  • [2024-10-04 22:27:39]
  • 评测
  • 测评结果:AC
  • 用时:354ms
  • 内存:13416kb
  • [2024-10-04 22:27:33]
  • 提交

answer

#include <bits/stdc++.h>
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<int, int> pii;
typedef std::pair<LL, int> pli;
typedef std::pair<LL, LL> pll;
#define fi first
#define se second
#define MP std::make_pair
LL read() {
	LL s = 0; int f = 1;
	char c = getchar();
	while (!(c >= '0' && c <= '9'))
		f ^= (c == '-'), c = getchar();
	while (c >= '0' && c <= '9')
		s = s * 10 + (c ^ 48), c = getchar();
	return f ? s : -s;
} 
const LL INF = 0x3f3f3f3f3f3f3f3fll;
const int N = 4e5 + 7, MOD = 998244353;
template<typename T> T& Fmax(T& x, T y) { return x = x < y ? y : x; };
template<typename T> T& Fmin(T& x, T y) { return x = x < y ? x : y; };
auto fplus = [](LL x, LL y) { return x + y < MOD ? x + y : x + y - MOD; };
auto fminus = [](LL x, LL y) { return x < y ? x - y + MOD : x - y; };
auto Fplus = [](LL &x, LL y) { x = fplus(x, y); };
auto Fminus = [](LL &x, LL y) { x = fminus(x, y); };

LL fpow(LL x, LL y = MOD - 2) {
	LL ans = 1; x %= MOD;
	for (; y; x = x * x % MOD, y >>= 1)
		if (y & 1) ans = ans * x % MOD;
	return ans;
}

bool isp[N];
LL n, m, tot, pr[N], f[2][N], ans = 1; 

LL id(LL x, LL y) { return x ? n / y : y; }
pll ID(LL x) { return x <= m ? MP(0, x) : MP(1, n / x); }

void Euler(int x) {
	memset(isp, 1, sizeof(isp));
	for (int i = 2; i <= x; i ++) {
		if (isp[i]) pr[++ tot] = i;
		for (int j = 1; j <= tot && i * pr[j] <= x; j ++) {
			isp[i * pr[j]] = false;
			if (i % pr[j] == 0) break;
		}
	}
} 

signed main() {
	n = read(), Euler(m = sqrtl(n));
	// std::cout << m << ' ' << m * m << ' ' << n << '\n';
	for (int i = 0; i <= 1; i ++)
		for (int j = 1; j <= m; j ++) f[i][j] = n / id(i, j) - 1;
	for (int i = 1; i <= tot; i ++) {
		LL lim = n / (pr[i] * pr[i]);
		for (int j = 1; j <= m && id(0, j) <= lim; j ++) {
			pll t = ID(id(0, j) * pr[i]);
			f[0][j] += i - 1 - f[t.fi][t.se]; 
		}
		for (int j = m; j && id(1, j) <= lim; j --) {
			pll t = ID(id(1, j) * pr[i]);
			f[1][j] += i - 1 - f[t.fi][t.se]; 
		}
	}
	for (LL l = 1, r, k; l <= n / 3; l = r + 1) {
		r = n / (n / l), k = n / l;
		pll t = ID(l); LL c = f[t.fi][t.se];
		if (l * 2 <= n) t = ID(l * 2), c -= f[t.fi][t.se];
		LL f = (k == 3 ? 3 : fpow(k, c) * ((k - c - 1) % MOD) % MOD);
		ans = ans * fpow(f, r - l + 1) % MOD;
//		std::cout << l << ' ' << r << ' ' << k << ' ' << c << ' ' << f << ' ' << ans << '\n';
	}
	std::cout << ans << '\n';
	return 0;
}
 

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 8148kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 2ms
memory: 7916kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 2ms
memory: 7988kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 0ms
memory: 8168kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 2ms
memory: 8092kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 2ms
memory: 8084kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 2ms
memory: 8084kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 2ms
memory: 8028kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 0ms
memory: 8120kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 3ms
memory: 8064kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 5ms
memory: 8284kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 17ms
memory: 8328kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 14ms
memory: 8272kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 24ms
memory: 10400kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 47ms
memory: 8644kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 117ms
memory: 11252kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 226ms
memory: 10616kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 309ms
memory: 10552kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 354ms
memory: 13416kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 352ms
memory: 10820kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 348ms
memory: 12296kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed