Pagini recente » Cod sursa (job #243666) | Cod sursa (job #373221) | Cod sursa (job #299783) | Cod sursa (job #1118570) | Cod sursa (job #914784)
Cod sursa(job #914784)
#include <iostream>
#include <fstream>
using namespace std;
int w,h,sq[1000005],n,m;
long long rez;
int check(int x,int b) {
return (x%2==0 && x>=0 && x/2<b);
}
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;
}
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<=500; ++i) sq[i*i]=i;
for(w=1; w<n; ++w) for(h=1; h<m; ++h) {
for(int a=0; a<=h/2; ++a) rez+=nsol(a)*2;
if(h%2==0) rez-=nsol(h/2);
rez-=nsol(h);
}
g<<rez;
return 0;
}