QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376989#5738. Square Sum369PaiWA 1ms3492kbC++141.6kb2024-04-04 20:01:562024-04-04 20:01:57

Judging History

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

  • [2024-04-04 20:01:57]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3492kb
  • [2024-04-04 20:01:56]
  • 提交

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)
{
	// cerr << "G(" << p << ',' << k << ',' << z << ")\n";
	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 - 2 : 0;
		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)
{
	// cerr << "F(" << p << ',' << k << ',' << z << ")\n";
	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)return G(p , k , 1) + (z % p == 0);
	if(k == 0)return 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3492kb

input:

3 3
0 1 2

output:

5 4 4 

result:

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