Pagini recente » Cod sursa (job #2242819) | Cod sursa (job #2461735) | Cod sursa (job #2973486) | Cod sursa (job #699106) | Cod sursa (job #998332)
Cod sursa(job #998332)
#include <cstdio>
const int MAX_SIZE(405);
int n, m;
long long Matrix [MAX_SIZE] [MAX_SIZE];
long long Result;
int Root [MAX_SIZE * MAX_SIZE];
inline void Read (void)
{
std::freopen("dreptunghiuri.in","r",stdin);
std::scanf("%d %d",&n,&m);
std::fclose(stdin);
}
inline void Print (void)
{
std::freopen("dreptunghiuri.out","w",stdout);
std::printf("%lld\n",Result);
std::fclose(stdout);
}
inline void Preprocess (void)
{
for (int i(1) ; i < MAX_SIZE ; ++i)
Root[i * i] = i;
--n;
--m;
}
inline void Compute (void)
{
int h, w, x1, x2, l, d, sum;
for (h = 1 ; h <= n ; ++h)
for (w = 1 ; w <= m ; ++w)
{
if (Matrix[w][h])
sum = Matrix[w][h];
else
{
for (l = sum = 0 ; l < h ; ++l)
{
d = w * w - 4 * l * (h - l);
if (d < 0 || (d && !Root[d]))
continue;
d = Root[d];
x1 = x2 = -1;
if ((w + d) % 2 == 0)
x1 = (w + d) / 2;
if ((w - d) % 2 == 0)
x2 = (w - d) / 2;
if (x1 >= 0 && x1 < w)
++sum;
if (x2 != x1 && x2 >= 0 && x2 < w)
++sum;
}
Matrix[h][w] = sum;
}
Result += (n - h + 1) * (m - w + 1) * sum;
}
}
int main (void)
{
Read();
Preprocess();
Compute();
Print();
return 0;
}