QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#376974#5738. Square Sum369PaiWA 19ms3832kbC++141.6kb2024-04-04 19:45:552024-04-04 19:45:55

Judging History

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

  • [2024-04-04 19:45:55]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:3832kb
  • [2024-04-04 19:45:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
map<tuple<int , int , int> , ll>mp;
ll G(int p , int k , int z)
{
	if(p == 2 && k <= 2)
	{
		int v = 1 << (k + 1) , ans = 0;
		for(int x = 0 ; x < v ; x++)
			for(int y = 0 ; y < v ; y++)
				if(x % 2 || y % 2)
					ans += (x * x + y * y) % v == z % v;
		return ans;
	}
	if(k <= 1)
	{
		int r = p % 4; z %= p;
		if(!z)return r == 1 ? 2 * p - 1 : 1;
		else return r == 1 ? p - 1 : p + 1;
	}
	if(mp.find({p , k , z}) != mp.end())
		return mp[{p , k , z}];
	return mp[{p , k , z}] = p * G(p , k - 1 , z);
}
ll F(int p , int k , int z)
{
	if(p == 2 && k <= 2)
	{
		int v = 1 << (k + 1) , ans = 0;
		for(int x = 0 ; x < v ; x++)
			for(int y = 0 ; y < v ; y++)
				ans += (x * x + y * y) % v == z % v;
		return ans;
	}
	if(k <= 1)
	{
		int r = p % 4; z %= p;
		if(!z)return r == 1 ? 2 * p - 1 : 1;
		else return r == 1 ? p - 1 : p + 1;
	}
	ll res = G(p , k , z) , p2 = (ll)p * p;
	if(z % p2 == 0)res += p2 * F(p , k - 2 , z / p2);
	return res;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0) , cout.tie(0);
	int m , q , t; vector<pair<int , int> >fac;
	cin >> m >> q; t = m;
	for(int i = 2 ; (ll)i * i <= t ; i++)
	{
		if(t % i == 0)
		{
			int k = 0;
			while(t % i == 0)t /= i , k++;
			fac.push_back({i , k});
		}
	}
	if(t > 1)fac.push_back({t , 1});
	// for(auto [p , k] : fac)cerr << p << "^" << k << '\n';
	while(q--)
	{
		int z; ll res = 1; cin >> z;
		for(auto [p , k] : fac)
			res = res * F(p , k - (p == 2) , z);
		cout << res << " ";
	}
	cout << "\n";
	return 0;
}

详细

Test #1:

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

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: 3484kb

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: 3548kb

input:

5 1
3

output:

4 

result:

ok 1 number(s): "4"

Test #4:

score: -100
Wrong Answer
time: 19ms
memory: 3832kb

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:

1698693120 1698693120 1698693120 1698693120 0 1698693120 1698693120 1698693120 3822059520 1698693120 0 1698693120 1698693120 1698693120 1698693120 1698693120 1698693120 256608000 1698693120 1698693120 1698693120 3822059520 1698693120 1698693120 256608000 256608000 1698693120 0 256608000 1698693120 2...

result:

wrong answer 9th numbers differ - expected: '3397386240', found: '3822059520'