QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#376964 | #5738. Square Sum | 369Pai | WA | 19ms | 3748kb | C++14 | 1.5kb | 2024-04-04 19:37:40 | 2024-04-04 19:37:40 |
Judging History
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 = k == 1 ? 2 : 4 , 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;
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 = k == 1 ? 2 : 4 , 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;
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});
while(q--)
{
int z; ll res = 1; cin >> z;
for(auto [p , k] : fac)res = res * F(p , k , z);
cout << res << " ";
}
cout << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3556kb
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: 3552kb
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: 3748kb
input:
5 1 3
output:
4
result:
ok 1 number(s): "4"
Test #4:
score: -100
Wrong Answer
time: 19ms
memory: 3492kb
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:
2335703040 2335703040 1698693120 849346560 0 2335703040 2335703040 2335703040 1698693120 2335703040 0 2335703040 1698693120 1698693120 1698693120 1698693120 849346560 641520000 1698693120 2335703040 2335703040 1698693120 2335703040 1698693120 641520000 641520000 1698693120 0 641520000 2335703040 641...
result:
wrong answer 1st numbers differ - expected: '1698693120', found: '2335703040'