QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#288909#5817. 小学生数学题FeelsGood100 ✓445ms169164kbC++141.4kb2023-12-23 14:12:512023-12-23 14:12:52

Judging History

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

  • [2023-12-23 14:12:52]
  • 评测
  • 测评结果:100
  • 用时:445ms
  • 内存:169164kb
  • [2023-12-23 14:12:51]
  • 提交

answer

#include <bits/stdc++.h>

#define ll long long
#define lll __int128

using namespace std;

namespace IO
{
	void read() {}
	template <typename T1, typename ...T2>
	void read(T1 &n, T2 &...m)
	{
		T1 op = 1;
		char c;
		while (isdigit(c = getchar()) == false)
			if (c == '-') op = -1;
		n = c ^ 48;
		while (isdigit(c = getchar()))
			n = (n << 1) + (n << 3) + (c ^ 48);
		n *= op;
		return read(m...);
	}
}

using IO::read;

namespace Solve
{
	const ll mod = 998244353;
	const int MaxN = 2e7, MaxP = 2e6;
	
	bitset<MaxN + 10> vis;
	ll f[MaxN + 10];
	int prm[MaxP + 10], cntp;
	
	ll qpow(ll n, ll k)
	{
		ll res = 1;
		while (k)
		{
			if (k & 1)
				res = (res % mod) * (n % mod) % mod;
			n = (n % mod) * (n % mod) % mod;
			k >>= 1;
		}
		return res;
	}
	
	void Sol()
	{
		ll n, k;
		read(n, k);
		f[1] = 1, vis[1] = true;
		ll frac = 1, ans = 1;
		for (int i = 2; i <= n; ++i)
		{
			if (vis[i] == false)
			{
				prm[++cntp] = i;
				f[i] = qpow(i, (mod - 2) * k);
			}
			frac *= i;
			frac %= mod;
			ans += frac * f[i] % mod;
			ans %= mod;
			for (int j = 1; j <= cntp && i * prm[j] <= n; ++j)
			{
				vis[i * prm[j]] = true;
				f[i * prm[j]] = (f[i] % mod) * (f[prm[j]] % mod) % mod;
				if (i % prm[j] == 0)
					break;
			}
		}
		printf("%lld\n", ans % mod);
	}
}

using Solve::Sol;

int main()
{
	Sol();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 217ms
memory: 83816kb

input:

9450395 1

output:

688545438

result:

ok single line: '688545438'

Test #2:

score: 10
Accepted
time: 201ms
memory: 79596kb

input:

8978812 1

output:

334565356

result:

ok single line: '334565356'

Test #3:

score: 10
Accepted
time: 205ms
memory: 80260kb

input:

8944235 1

output:

982802915

result:

ok single line: '982802915'

Test #4:

score: 10
Accepted
time: 154ms
memory: 65812kb

input:

7081118 3

output:

599009773

result:

ok single line: '599009773'

Test #5:

score: 10
Accepted
time: 178ms
memory: 71716kb

input:

7904241 3

output:

871243720

result:

ok single line: '871243720'

Test #6:

score: 10
Accepted
time: 217ms
memory: 86412kb

input:

9921275 3

output:

549818101

result:

ok single line: '549818101'

Test #7:

score: 10
Accepted
time: 402ms
memory: 150852kb

input:

17575748 14135489

output:

69236780

result:

ok single line: '69236780'

Test #8:

score: 10
Accepted
time: 439ms
memory: 169164kb

input:

19858362 14822524

output:

239890381

result:

ok single line: '239890381'

Test #9:

score: 10
Accepted
time: 445ms
memory: 161604kb

input:

18848696 15530895

output:

88125041

result:

ok single line: '88125041'

Test #10:

score: 10
Accepted
time: 392ms
memory: 153076kb

input:

17787945 13890407

output:

989967864

result:

ok single line: '989967864'

Extra Test:

score: 0
Extra Test Passed