def solve(N, X, D):

    if D == 0:

        if X == 0:

            return 1

        return N+1

    L = {0: [(0, 1), (1, -1)]}

    coef_l = 0

    coef_r = 1

    for coef_x in range(1, N+1):

        m = X * coef_x % D

        l = X * coef_x // D + coef_l

        r = X * coef_x // D + coef_x * N - coef_r

        coef_l = coef_r

        coef_r += coef_x + 1

        if m not in L:

            L[m] = []

        L[m].append((l, 1))

        L[m].append((r+1, -1))

    ans = 0

    #print(L)

    for Q in list(L.values()):

        Q.sort()

        cnt = 0

        last = None

        for val, sign in Q:

            if cnt > 0:

                ans += val - last

            cnt += sign

            last = val

    return ans



N, X, D = list(map(int, input().split()))

print((solve(N, X, D)))

import os

import sys

#import numpy as np



def solve(N, X, D):

    if D == 0:

        if X == 0:

            return 1

        return N+1

    #L = {0: [(0, 1), (1, -1)]}

    L = [[(0, 1), (1, -1)]]

    mapping = {0: 0}

    coef_l = 0

    coef_r = 1

    for coef_x in range(1, N+1):

        m = X * coef_x % D

        l = X * coef_x // D + coef_l

        r = X * coef_x // D + coef_x * N - coef_r

        coef_l = coef_r

        coef_r += coef_x + 1

        if m not in mapping:

            mapping[m] = len(L)

            L.append([(0, 0)] * 0)

        idx_L = mapping[m]

        L[idx_L].append((l, 1))

        L[idx_L].append((r+1, -1))

    ans = 0

    for Q in L:

        Q.sort()

        cnt = 0

        last = None

        for val, sign in Q:

            if cnt > 0:

                ans += val - last

            cnt += sign

            last = val

    return ans



# >>> numba compile >>>

numba_config = [

    [solve, "i8(i8,i8,i8)"],

]

if sys.argv[-1] == "ONLINE_JUDGE":

    from numba import njit

    from numba.pycc import CC

    cc = CC("my_module")

    for func, signature in numba_config:

        vars()[func.__name__] = njit(signature)(func)

        cc.export(func.__name__, signature)(func)

    cc.compile()

    exit()

elif os.name == "posix":

    exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")

else:

    from numba import njit

    for func, signature in numba_config:

        vars()[func.__name__] = njit(signature, cache=True)(func)

    print("compiled!", file=sys.stderr)

# <<< numba compile <<<





N, X, D = map(int, input().split())

print(solve(N, X, D))

def solve(N, X, D):
    if D == 0:
        if X == 0:
            return 1
        return N + 1
    L = {0: [(0, 1), (1, -1)]}
    coef_l = 0
    coef_r = 1
    for coef_x in range(1, N + 1):
        m = X * coef_x % D
        l = X * coef_x // D + coef_l
        r = X * coef_x // D + coef_x * N - coef_r
        coef_l = coef_r
        coef_r += coef_x + 1
        if m not in L:
            L[m] = []
        L[m].append((l, 1))
        L[m].append((r + 1, -1))
    ans = 0
    # print(L)
    for Q in list(L.values()):
        Q.sort()
        cnt = 0
        last = None
        for val, sign in Q:
            if cnt > 0:
                ans += val - last
            cnt += sign
            last = val
    return ans


N, X, D = list(map(int, input().split()))
print((solve(N, X, D)))

import os
import sys

# import numpy as np
def solve(N, X, D):
    if D == 0:
        if X == 0:
            return 1
        return N + 1
    # L = {0: [(0, 1), (1, -1)]}
    L = [[(0, 1), (1, -1)]]
    mapping = {0: 0}
    coef_l = 0
    coef_r = 1
    for coef_x in range(1, N + 1):
        m = X * coef_x % D
        l = X * coef_x // D + coef_l
        r = X * coef_x // D + coef_x * N - coef_r
        coef_l = coef_r
        coef_r += coef_x + 1
        if m not in mapping:
            mapping[m] = len(L)
            L.append([(0, 0)] * 0)
        idx_L = mapping[m]
        L[idx_L].append((l, 1))
        L[idx_L].append((r + 1, -1))
    ans = 0
    for Q in L:
        Q.sort()
        cnt = 0
        last = None
        for val, sign in Q:
            if cnt > 0:
                ans += val - last
            cnt += sign
            last = val
    return ans


# >>> numba compile >>>
numba_config = [
    [solve, "i8(i8,i8,i8)"],
]
if sys.argv[-1] == "ONLINE_JUDGE":
    from numba import njit
    from numba.pycc import CC

    cc = CC("my_module")
    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature)(func)
        cc.export(func.__name__, signature)(func)
    cc.compile()
    exit()
elif os.name == "posix":
    exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
else:
    from numba import njit

    for func, signature in numba_config:
        vars()[func.__name__] = njit(signature, cache=True)(func)
    print("compiled!", file=sys.stderr)
# <<< numba compile <<<
N, X, D = map(int, input().split())
print(solve(N, X, D))

+import os +import sys + +# import numpy as np -    L = {0: [(0, 1), (1, -1)]} +    # L = {0: [(0, 1), (1, -1)]} +    L = [[(0, 1), (1, -1)]] +    mapping = {0: 0} -        if m not in L: -            L[m] = [] -        L[m].append((l, 1)) -        L[m].append((r + 1, -1)) +        if m not in mapping: +            mapping[m] = len(L) +            L.append([(0, 0)] * 0) +        idx_L = mapping[m] +        L[idx_L].append((l, 1)) +        L[idx_L].append((r + 1, -1)) -    # print(L) -    for Q in list(L.values()): +    for Q in L: -N, X, D = list(map(int, input().split())) -print((solve(N, X, D))) +# >>> numba compile >>> +numba_config = [ +    [solve, "i8(i8,i8,i8)"], +] +if sys.argv[-1] == "ONLINE_JUDGE": +    from numba import njit +    from numba.pycc import CC + +    cc = CC("my_module") +    for func, signature in numba_config: +        vars()[func.__name__] = njit(signature)(func) +        cc.export(func.__name__, signature)(func) +    cc.compile() +    exit() +elif os.name == "posix": +    exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}") +else: +    from numba import njit + +    for func, signature in numba_config: +        vars()[func.__name__] = njit(signature, cache=True)(func) +    print("compiled!", file=sys.stderr) +# <<< numba compile <<< +N, X, D = map(int, input().split()) +print(solve(N, X, D))