Cod sursa(job #2429366)

Utilizator georgerapeanuRapeanu George georgerapeanu Data 9 iunie 2019 13:04:56
Problema Dreptunghiuri Scor 80
Compilator cpp-64 Status done
Runda Lista lui wefgef Marime 1.11 kb
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

FILE *f = fopen("dreptunghiuri.in","r");
FILE *g = fopen("dreptunghiuri.out","w");

int n,m;

int main(){

    fscanf(f,"%d %d",&n,&m);

    n--;m--;

    long long ans = 0;

    for(int h = 1;h <= n;h++){
        for(int w = 1;w <= m;w++){
            long long total = -3;
            for(int deltah_2 = h % 2;deltah_2 <= h;deltah_2 += 2){
                long long deltaw_p_2 = -1LL * h * h + 1LL * deltah_2 * deltah_2  + 1LL * w * w;
                int deltaw_2 = sqrt(deltaw_p_2);
                if(1LL * deltaw_2 * deltaw_2 != deltaw_p_2){
                    deltaw_2++;
                }
                if(1LL * deltaw_2 * deltaw_2 != deltaw_p_2){
                    continue;
                }
                if(deltaw_2 > w || (deltaw_2 % 2) != (w % 2)){
                    continue;
                }
                total +=  (1 + (deltah_2 != 0)) * (1 + (deltaw_2 != 0));
            }
            ans += total * (n - h + 1) * (m - w + 1);
        }
    }

    fprintf(g,"%lld\n",ans);

    fclose(f);
    fclose(g);

    return 0;
}