Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
/*
小数の桁数を指定する
	cout << setprecision(8)<< mp[0]-mx << endl;
*/

ll m[128][128][13000] = {0};
int main()
{
	ll i,j,k,a,b,ans=0;
	char c;
	ll N,M,T, X,Y;
	cin >>N>>M>>T;
	map<ll, std::vector<ll> > mp;
	if(T==0)
	{
		if(M==0)
			ans = 1;
		else
			ans = N+1;
	}
	else{
		if(T<0)
		{
			T = -T;
			M = -M;
		}
		X = M;
		while(X<0)
			X += T;
		for(i=0;i<=N;++i)
		{
			Y = (X*i)%T;
			a = 0;
			for(j=0;j<i;++j)
				a += j;
			mp[Y].push_back((a+((M*i)-Y)/T)*2);
			a = 0;
			for(j=0;j<i;++j)
				a += N-j-1;
			mp[Y].push_back((a+((M*i)-Y)/T+1)*2+1);
		}
		ans = 0;
		for(auto itr=mp.begin();itr !=mp.end();++itr)
		{
			auto vec = itr->second;
			if(vec.size() == 2)
			{
				ans += (vec[1]>>1)-(vec[0]>>1);
				return;
			}
			sort(vec.begin(), vec.end());
			int md = 0;
			int bef = 0;
			for(auto it=vec.begin(); it!=vec.end(); ++it)
			{
				if(md > 0)
					ans += ((*it)>>1) - bef;
				bef = ((*it)>>1);
				if((*it)&1)
					md-=1;
				else
					md += 1;
			}
		}
	}
	cout << ans << endl;
	return 0;
}




















Compiler output:
a.cc: In function 'int main()':
a.cc:174:33: error: return-statement with no value, in function returning 'int' [-fpermissive]
  174 |                                 return;
      |                                 ^~~~~~