Pagini recente » Cod sursa (job #809136) | Cod sursa (job #2183095) | Cod sursa (job #242774) | Cod sursa (job #1876936) | Cod sursa (job #2260723)
#include <fstream>
#define N 405
using namespace std;
int ispp[N*N],root[N*N],nrdrept[N][N];
int main()
{
ifstream f("dreptunghiuri.in");
ofstream g("dreptunghiuri.out");
int n,m;
f>>n>>m;
n--;
m--;
for(int i=1;i<=400;i++)
{
ispp[i*i]=1;
root[i*i]=i;
}
for(int l=1;l<=n;l++)
for(int L=1;L<=m;L++)
for(int b=1;b<l;b++)
{
int delta=L*L-4*(l*b-b*b);
if(delta<0)
continue;
if(delta==0 and L%2==0)
nrdrept[l][L]++;
if(delta>0 and ispp[delta])
{
int x1=L-root[delta];
if(x1%2==0 and x1>0)
nrdrept[l][L]++;
int x2=L+root[delta];
if(x2%2==0 and x2/2<L)
nrdrept[l][L]++;
}
}
long long sol=0;
for(int l=1;l<=n;l++)
for(int L=1;L<=m;L++)
sol+=(nrdrept[l][L]+1)*(n-l+1)*(m-L+1);
g<<sol;
return 0;
}