Cod sursa(job #2429371)

Utilizator georgerapeanuRapeanu George georgerapeanu Data 9 iunie 2019 13:09:05
Problema Dreptunghiuri Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.04 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;
            int deltaw_2 = (w % 2);
            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;
                
                while(deltaw_2 < w && 1LL * deltaw_2 * deltaw_2 < deltaw_p_2){
                    deltaw_2 += 2;
                }
                
                if(1LL * deltaw_2 * deltaw_2 != deltaw_p_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;
}