QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#153047#5738. Square Sumle0nWA 17ms1692kbC++141.5kb2023-08-29 09:59:322023-08-29 09:59:32

Judging History

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

  • [2023-08-29 09:59:32]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:1692kb
  • [2023-08-29 09:59:32]
  • 提交

answer

#include <cstdio>

using namespace std;
typedef long long ll;

const int mod = 998244353;
int pr[105], pw[105];
int pww[105][105];
int f2[4][8], c;
int f(int p, int z, int k)
{
	int tmp, ans, q = 2 * (((pr[p] + 1) / 2) & 1) - 1;
	if(pr[p] == 2)
	{
		tmp = ((k > 3) ? pww[p][k - 3] : 1);
		k = ((k > 3) ? 3 : k);
		ans = (ll)tmp * f2[k][z & ((1 << k) - 1)] % mod;
	}
	else
		ans = (ll)pww[p][k - 1] * ((z % pr[p]) ? (pr[p] - q) : ((pr[p] - 1) * (q + 1))) % mod;
	return ans;
}
int g(int p, int z, int k)
{
	if(!k)
		return 1;
	int res = 0;
	if(k > 1 && !(z % pww[p][2]))
		res = (ll)pww[p][2] * g(p, z / pww[p][2], k - 2) % mod;
	if(k == 1 && !(z % pr[p]))
		res = 1;
	return (res + f(p, z, k)) % mod;
}
void work(int m)
{
	int i;
	c = 0;
	for(i = 2; (ll)i * i <= m; i++)
		if(!(m % i))
		{
			pr[++c] = i;
			pww[c][pw[c] = 0] = 1;
			while(!(m % i))
			{
				pww[c][pw[c] + 1] = pww[c][pw[c]] * i;
				++pw[c];
				m /= i;
			}
		}
	if(m > 1)
	{
		pr[++c] = m;
		pw[c] = 1;
		pww[c][0] = 1;
		pww[c][1] = m;
	}
}

int main()
{
	int n, m, i, j, k, z, ans;
	for(i = 1; i <= 3; i++)
		for(j = 0; j < (1 << i); j++)
			for(k = 0; k < (1 << i); k++)
				if((j | k) & ((1 << (i - 1)) - 1))
				f2[i][(j * j + k * k) & ((1 << i) - 1)]++;
	scanf("%d%d", &m, &n);
	work(m);
	while(n--)
	{
		scanf("%d", &z);
		ans = 1;
		for(i = 1; i <= c; i++)
			ans = (ll)ans * g(i, z, pw[i]) % mod;
		printf("%d\n", ans);
	}
	return 0;
}

詳細信息

Test #1:

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

input:

3 3
0 1 2

output:

1
4
4

result:

ok 3 number(s): "1 4 4"

Test #2:

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

input:

4 4
0 1 2 3

output:

4
8
4
0

result:

ok 4 number(s): "4 8 4 0"

Test #3:

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

input:

5 1
3

output:

4

result:

ok 1 number(s): "4"

Test #4:

score: -100
Wrong Answer
time: 17ms
memory: 1652kb

input:

735134400 100000
4 4 1 2 3 4 4 4 5 4 3 4 1 1 1 1 2 0 1 4 4 5 4 1 0 0 1 3 0 4 0 5 3 0 3 0 5 4 0 0 3 2 5 3 2 4 3 4 2 1 3 3 2 2 2 3 1 0 1 2 3 4 3 5 4 4 0 1 5 2 2 3 3 2 4 3 5 5 1 3 1 1 4 3 4 3 4 5 2 4 1 3 2 0 5 0 0 5 5 1 2 0 3 4 0 4 1 0 1 4 5 5 3 1 3 0 3 5 0 4 2 0 4 0 0 0 4 0 2 2 2 4 5 3 0 2 0 4 1 4 1 2...

output:

551550974
551550974
700448767
700448767
0
551550974
551550974
551550974
402653181
551550974
0
551550974
700448767
700448767
700448767
700448767
700448767
61776000
700448767
551550974
551550974
402653181
551550974
700448767
61776000
61776000
700448767
0
61776000
551550974
61776000
402653181
0
6177600...

result:

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