QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#611733#9309. GraphwjcWA 107ms12488kbC++142.4kb2024-10-04 22:25:312024-10-04 22:25:33

Judging History

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

  • [2024-10-04 22:25:33]
  • 评测
  • 测评结果:WA
  • 用时:107ms
  • 内存:12488kb
  • [2024-10-04 22:25:31]
  • 提交

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);
		ans = ans * fpow(f, r - l + 1) % MOD;
//		std::cout << l << ' ' << r << ' ' << k << ' ' << c << ' ' << f << ' ' << ans << '\n';
	}
	std::cout << ans << '\n';
	return 0;
}
 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 8172kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 1ms
memory: 6092kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 8156kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 1ms
memory: 8172kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 1ms
memory: 8228kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 1ms
memory: 9848kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

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

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 16ms
memory: 8320kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 12ms
memory: 10228kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 23ms
memory: 10148kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

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

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: -100
Wrong Answer
time: 107ms
memory: 11316kb

input:

19834593299

output:

-768482857

result:

wrong answer expected '523663743', found '-768482857'