QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#376989 | #5738. Square Sum | 369Pai | WA | 1ms | 3492kb | C++14 | 1.6kb | 2024-04-04 20:01:56 | 2024-04-04 20:01:57 |
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)
{
// 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'