QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#376991#5738. Square Sum369PaiTL 49ms3832kbC++141.6kb2024-04-04 20:02:412024-04-04 20:02:42

Judging History

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

  • [2024-04-04 20:02:42]
  • 评测
  • 测评结果:TL
  • 用时:49ms
  • 内存:3832kb
  • [2024-04-04 20:02:41]
  • 提交

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 , 1 , z) + (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;
}

详细

Test #1:

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

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

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

input:

5 1
3

output:

4 

result:

ok 1 number(s): "4"

Test #4:

score: 0
Accepted
time: 18ms
memory: 3560kb

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 3397386240 1698693120 0 1698693120 1698693120 1698693120 1698693120 1698693120 1698693120 30888000 1698693120 1698693120 1698693120 3397386240 1698693120 1698693120 30888000 30888000 1698693120 0 30888000 1698693120 30888...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 14ms
memory: 3588kb

input:

735134400 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 30888000 308...

result:

ok 100000 numbers

Test #6:

score: 0
Accepted
time: 17ms
memory: 3564kb

input:

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

output:

1073741824 536870912 1073741824 1073741824 0 1073741824 0 1073741824 1073741824 1073741824 536870912 1073741824 1073741824 1073741824 1073741824 536870912 1073741824 1073741824 1073741824 1073741824 0 1073741824 1073741824 1073741824 0 1073741824 1073741824 1073741824 1073741824 536870912 1073741824...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 34ms
memory: 3600kb

input:

536870912 100000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 ...

result:

ok 100000 numbers

Test #8:

score: 0
Accepted
time: 49ms
memory: 3652kb

input:

536870912 100000
268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268435456 268...

output:

536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 536870912 ...

result:

ok 100000 numbers

Test #9:

score: -100
Time Limit Exceeded

input:

536870912 100000
504070704 500101584 484480320 75189632 133364432 237444928 506874208 477655312 261146688 36394912 312952944 260479168 77969872 60413040 249853392 288067360 129948656 311385424 444949024 339508400 62885472 368704208 379750624 528964784 158077280 415604832 393291776 342918080 20621644...

output:

0 1073741824 1073741824 0 1073741824 1073741824 0 1073741824 1073741824 1073741824 0 0 1073741824 0 1073741824 1073741824 0 1073741824 1073741824 0 0 1073741824 0 0 0 0 1073741824 0 1073741824 0 0 1073741824 1073741824 1073741824 0 0 0 1073741824 0 0 0 0 0 0 1073741824 1073741824 0 1073741824 0 0 0 ...

result: