B. Divide Candies

sample 2 (n=6, m=5)

f:id:peroon:20200813222540p:plain

int main(){
    // input
    ll n,m;cin>>n>>m;
    
    ll sum=0;
    FOR(y,1,m+1){
      FOR(x,1,m+1){
        ll a = x*x+y*y;
        if(a%m==0){
          if(x<=n && y<=n){
            // いくつあるか?
            ll y_num = (n-y+1+m-1)/m;
            ll x_num = (n-x+1+m-1)/m;
            sum += y_num * x_num;
          }
        }
      }
    }
    p(sum);

    return 0;
}