Pagini recente » Cod sursa (job #87522) | Cod sursa (job #2206203) | Cod sursa (job #525496) | Cod sursa (job #185390) | Cod sursa (job #914787)
Cod sursa(job #914787)
#include <iostream>
#include <fstream>
using namespace std;
int w,h,sq[400*401],n,m;
long long rez;
inline int check(int x,int b) {
return (x%2==0 && x>=0 && x/2<b);
}
inline int calc(int b, int c) {
int d=b*b-4*c;
if(d==0) return check(b,b);
else if(d>0 && sq[d])
return check(b-sq[d],b)+check(b+sq[d],b);
return 0;
}
inline long long nsol(int x) {
return calc(w,x*(h-x))*1LL*(n-w)*(m-h);
}
int main()
{
ifstream f("dreptunghiuri.in");
ofstream g("dreptunghiuri.out");
f>>n>>m;
for(int i=1; i<=400; ++i) sq[i*i]=i;
for(w=1; w<n; ++w) for(h=1; h<m; ++h) {
for(int a=0; 2*a<=h; ++a) rez+=nsol(a)*2;
if(h%2==0) rez-=nsol(h/2);
rez-=nsol(h);
}
g<<rez;
return 0;
}