QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#714585 | #7704. Plus Minus Four Squares | rand123 | AC ✓ | 2ms | 3696kb | C++14 | 2.7kb | 2024-11-06 00:41:25 | 2024-11-06 00:41:26 |
Judging History
answer
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pb push_back
#define yes "YES"
#define no "NO"
#define ll long long
#define MOD 1000000007
#define all(x) x.begin(),x.end()
#define MOD2 998244353
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(int cas){
ll n;
cin>>n;
ll res = 0;
for (int i = 0; i<=(int)sqrt(n); i++){
for (int sub = 0; sub < i; sub++){
for (int add = 0; add < sub; add++){
ll curr = i*i - sub*sub + add*add;
if (curr <= n){
ll diff = abs(n - curr);
ll sq = sqrtl(diff);
if (sq*sq==diff && sq <= add) res++;
}
else{
ll diff = abs(n - curr);
ll sq = sqrtl(diff);
if (sq*sq==diff && sq < add) res++;
}
}
for (int sub2 = 0; sub2 <= sub; sub2++){
ll curr = i*i - sub2*sub2 - sub*sub;
if (curr <= n){
ll diff = abs(n - curr);
ll sq = sqrtl(diff);
if (sq*sq==diff && sq < sub2) res++;
}
else{
ll diff = abs(n - curr);
ll sq = sqrtl(diff);
if (sq*sq==diff && sq <= sub2) res++;
}
}
}
for (int add = 0; add <= i; add++){
for (int add2 = 0; add2 <= add; add2++){
ll curr = i*i + add*add + add2*add2;
if (curr <= n){
ll diff = abs(n - curr);
ll sq = sqrtl(diff);
if (sq*sq==diff && sq <= add2) res++;
}
else{
ll diff = abs(n - curr);
ll sq = sqrtl(diff);
if (sq*sq==diff && sq < add2) res++;
}
}
for (int sub2 = 0; sub2 < add; sub2++){
ll curr = i*i - sub2*sub2 + add*add;
if (curr <= n){
ll diff = abs(n - curr);
ll sq = sqrtl(diff);
if (sq*sq==diff && sq < sub2) res++;
}
else{
ll diff = abs(n - curr);
ll sq = sqrtl(diff);
if (sq*sq==diff && sq <= sub2) res++;
}
}
}
}
cout<<res<<'\n';
}
int main(){
int t=1;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//cin>>t;
for (int i = 1; i<=t; i++){
solve(i);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
64
output:
12
result:
ok single line: '12'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
65
output:
10
result:
ok single line: '10'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
2023
output:
245
result:
ok single line: '245'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
0
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 2ms
memory: 3696kb
input:
5000
output:
951
result:
ok single line: '951'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3612kb
input:
1024
output:
182
result:
ok single line: '182'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3676kb
input:
2048
output:
355
result:
ok single line: '355'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3608kb
input:
4096
output:
708
result:
ok single line: '708'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
1
output:
1
result:
ok single line: '1'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
2
output:
1
result:
ok single line: '1'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3680kb
input:
4
output:
2
result:
ok single line: '2'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
3
output:
1
result:
ok single line: '1'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
1111
output:
131
result:
ok single line: '131'