Problem:


Score : 600 points

Problem Statement

Consider the following arithmetic progression with n terms:

x, x + d, x + 2d, \ldots, x + (n-1)d

What is the product of all terms in this sequence?
Compute the answer modulo 1\ 000\ 003.

You are given Q queries of this form.
In the i-th query, compute the answer in case x = x_i, d = d_i, n = n_i.

Constraints

1 \leq Q \leq 10^5

0 \leq x_i, d_i \leq 1\ 000\ 002

1 \leq n_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

Q
x_1 d_1 n_1
:
x_Q d_Q n_Q

Output

Print Q lines.

In the i-th line, print the answer for the i-th query.

Sample Input 1

2
7 2 4
12345 67890 2019

Sample Output 1

9009
916936

For the first query, the answer is 7 \times 9 \times 11 \times 13 = 9009.
Don't forget to compute the answer modulo 1\ 000\ 003.



Sample input:
2
7 2 4
12345 67890 2019


Sample output:
9009
916936

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
q = int(input())

p=1000003

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % p
    elif y % 2 == 0 : return power(x, y//2)**2 % p
    else            : return power(x, y//2)**2 * x % p
    
factorial_list=[1 for i in range(p)]
for i in range(1,p):
    factorial_list[i]=factorial_list[i-1]*i%p
    
inv_list=[1 for i in range(p)]
inv_list[-1]=factorial_list[-1]
for i in range(p-1,1,-1):
    inv_list[i-1]=inv_list[i]*i%p
    
for i in range(q):
    x,d,n=(int(i) for i in input().split())
    if d==0:
        ans=power(x,n)
        print(ans%p)
    elif x<=p*d<=x+(n-1)*d:
        print(0)
    else:
        x=x*power(d,p-2)%p
        ans=factorial_list[x+n-1]*inv_list[x-1]*power(d,n)
        print(ans%p)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
q = int(input())

p=1000003

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % p
    elif y % 2 == 0 : return power(x, y//2)**2 % p
    else            : return power(x, y//2)**2 * x % p
    
factorial_list=[1 for i in range(p)]
for i in range(1,p):
    factorial_list[i]=factorial_list[i-1]*i%p
    
inv_list=[1 for i in range(p)]
inv_list[-1]=factorial_list[-1]
for i in range(p-1,1,-1):
    inv_list[i-1]=inv_list[i]*i%p
    
for i in range(q):
    x,d,n=(int(i) for i in input().split())
    if d==0:
        ans=power(d,p-2)
        print(ans)
    elif x<=p*d<=x+(n-1)*d:
        print(0)
    else:
        x=x*power(d,p-2)%p
        ans=factorial_list[x+n-1]*inv_list[x-1]*power(d,n)
        print(ans%p)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
q = int(input())

p=1000003
    
factorial_list=[1 for i in range(p)]
for i in range(1,p):
    factorial_list[i]=factorial_list[i-1]*i%p
    
inv_list=[1 for i in range(p)]
inv_list[-1]=factorial_list[-1]
for i in range(p-1,1,-1):
    inv_list[i-1]=inv_list[i]*i%p
    
for i in range(q):
    x,d,n=(int(i) for i in input().split())
    if d==0:
        ans=pow(x,n,p)
        print(ans)
    elif x<=p*d<=x+(n-1)*d:
        print(0)
    else:
        x=x*pow(d,p-2,p)%p
        ans=factorial_list[x+n-1]*inv_list[x-1]*pow(d,n,p)
        print(ans%p)

Submission status: Runtime Error

Solution code:
# 入力
Q = int(input())
x, d, n = (
    zip(*(map(int, input().split()) for _ in range(Q))) if Q else
    ((), (), ())
)

MOD = 1_000_003


class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(
                pow(self.x, other.x, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    def __radd__(self, other):
        return ModInt(other + self.x)

    def __rsub__(self, other):
        return ModInt(other - self.x)

    def __rmul__(self, other):
        return ModInt(other * self.x)

    def __rtruediv__(self, other):
        return ModInt(other * pow(self.x, MOD - 2, MOD))

    def __rpow__(self, other):
        return ModInt(pow(other, self.x, MOD))


# MOD未満の整数について、階乗を求めておく
# 各クエリに対して、d^n * (x/d + (n - 1))! / ((x/d) - 1)! を回答する
f = [0 for _ in range(MOD)]
f[0] = ModInt(1)
for i in range(1, MOD):
    f[i] = i * f[i - 1]

ans = '\n'.join(
    str(
        X**N if D == 0 else
        D**N * f[(X / D).x + N - 1] / f[(X / D).x - 1] if (X / D).x + N - 1 < MOD else
        0
    )
    for X, D, N in zip(map(ModInt, x), d, n)
)

# 出力
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return map(int, input().split())


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod//i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n-r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.MOD


M = 1000003
m = Mod(M)
C = Combination(M-1, M)


def slv(x, d, n):
    if d == 0:
        return m.pow(x, n)

    xd = m.div(x, d)
    if n > M - xd:
        return 0

    return m.mul(m.mul(C.g1[xd+n-1], C.g2[xd-1]), m.pow(d, n))


def main():
    Q = read_int()
    for _ in range(Q):
        x, d, n = read_int_n()
        print(slv(x, d, n))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def inpl(): return list(map(int, input().split()))
Q = int(input())
 
MOD = 10**6 + 3
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
 
size = MOD + 1
g1, g2, inverse = [0]*size, [0]*size, [0]*size
 
g1[:2] = [1, 1] # 元テーブル
g2[:2] = [1, 1] #逆元テーブル
inverse[:2] = [0, 1] #逆元テーブル計算用テーブル

for i in range(2, size):
    g1[i] =  ( g1[i-1] * i ) % MOD 
    inverse[i] = (-inverse[MOD % i] * (MOD//i) ) % MOD 
    g2[i] =  (g2[i-1] * inverse[i]) % MOD

for _ in range(Q):
    x, d, n = inpl()
    print((g1[n] * cmb((x*inverse[d] + n - 1)%MOD, n, MOD) * pow(d, n, MOD))%MOD)

Submission status: Runtime Error

Solution code:
mod = 10 ** 6 + 3

W = [1] * (mod)
for i in range(mod - 1):
	W[i + 1] = ((i + 1) * W[i]) % mod

def rev(a):
	return pow(a, mod - 2, mod)

def f(x, d, n):
	if d == 0:
		return pow(x, n, mod)
	else:
		d_r = rev(d)
		xdr = d_r * x % mod
		if xdr == 0:
			return 0
		elif (xdr + n - 1) >= mod:
			return 0
		else:
			return (W[xdr + n - 1] * rev(W[xdr - 1]) % mod) * pow(d, n, mod) % mod

ans = []
q = int(input())
for _ in range(q):
    x,d,n = map(int,input().split())
    ans.append(f(x,d,n))
print("\n".join(ans))

Submission status: Runtime Error

Solution code:
Q = int(input())

mod = 10 ** 6 + 3
table = [1]
for i in range(1, mod):
    table.append(table[-1]*i % mod)

for i in range(Q):
    x, d, n = map(int, input().split())
    if d == 0:
        print(pow(x, n, mod))
    else:
        y = x * pow(d, mod - 2, mod)% mod
        print(pow(d, n, mod) * table[y + n - 1] * pow(table[y - 1], mod - 2, mod) % mod)

Submission status: Runtime Error

Solution code:
Q = int(input())

mod = 10 ** 6 + 3
table = [1]
for i in range(1, mod):
    table.append(table[-1]*i % mod)

for i in range(Q):
    x, d, n = map(int, input().split())
    if d == 0:
        print(pow(x, n, mod))
    else:
        print(pow(d, n, mod) * table[y + n - 1] * pow(table[y - 1], mod - 2, mod) % mod)

Submission status: Runtime Error

Solution code:
t = int(input())
for i in range(t):
	a,d,n = list(map(int,input().split()))
	arr=arr%mod
    prod = 1
    mod=1000003
    for i in range(n):
        prod=prod*(a%mod)
        prod=prod%mod
        a+=d
    print(prod)

Submission status: Runtime Error

Solution code:
import numpy as np
t = int(input())
for i in range(t):
  a,d,n=list(map(int,input().split()))
  arr=np.arange(a,a+(n)*d,d)
  print(np.prod(arr)%1000003)

Submission status: Runtime Error

Solution code:
import numpy as np
t = int(input())
for i in range(t):
  a,d,n=list(map(int,input().split()))
  arr=np.linspace(a,d,n)
  print(np.mul(arr)%1000003)

Submission status: Runtime Error

Solution code:
l = raw_input().split()
Q = int(l[0])
X = []
D = []
N = []
for i in range(Q):
    l = raw_input().split()
    X.append(int(l[0]))
    D.append(int(l[1]))
    N.append(int(l[2]))

# print(Q, X, D, N)

for i in range(Q):
    x = X[i]
    d = D[i]
    n = N[i]
    cds = [0]*n
    cds[0] = 1
    cds_tmp = [0]*n
    ans = x
    # print(x, d, n)
    for j in range(1, n):
        # print('j={}'.format(j), cds)
        for k in range(1, j + 1):
            # print(j, k, j + 1 - k)
            cds[j + 1 - k] += cds[j - k] * j
            cds[k] %= 1000003
     #       print(k, cds[k - 1], cds_tmp)
    # print(cds)
    ans = 0
    x_n = [x]*n
    for i in range(1, n):
        x_n[i] = x_n[i - 1] * x
        x_n[i] %= 1000003
    # print('x_n', x_n)
    d_n = 1
    for i in range(n):
        # print(x_n[n - i - 1], cds[i], d_n)
        ans += x_n[n - i - 1] * cds[i] * d_n
        d_n *= d
        d_n %= 1000003
        ans %= 1000003
    print(ans)

Submission status: Runtime Error

Solution code:
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 1000003
from functools import reduce
import sys
sys.setrecursionlimit(10**7)


Max = mod-1
#二項係数とその逆元テーブルを作る前処理
fac = [0]*(Max)
finv = [0]*(Max)
inv = [0]*(Max)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,Max):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
#O(1)でmod計算した組合せ数を計算
def Comb(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod


Q = int(input())
def query(x,d,n):
    if x == 0:
        return 0
    if d == 0:
        return pow(x,n,mod)
    k = (x*inv[d])%mod
    if k+n-1 >= mod:
        return 0
    ans = fac[k+n-1]*finv[k-1]%mod
    ans *= pow(d,n,mod)
    ans %= mod
    return ans
for i in range(Q):
    x,d,n = map(int,input().split())
    print(query(x,d,n))

Submission status: Runtime Error

Solution code:
from itertools import*
import math
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 1000003
from functools import reduce
import sys
sys.setrecursionlimit(10**7)
input=sys.stdin.readline

Max = mod-1
#二項係数とその逆元テーブルを作る前処理
fac = [0]*(Max)
finv = [0]*(Max)
inv = [0]*(Max)
fac[0]=fac[1]=1
finv[0]=finv[1]=1
inv[1]=1
for i in range(2,Max):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i]*(mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
#O(1)でmod計算した組合せ数を計算
def Comb(n,r):
    if n < r:
        return 0
    if n < 0 or r < 0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%mod)%mod


Q = int(input())
def query(x,d,n):
    if x == 0:
        return 0
    if d == 0:
        return pow(x,n,mod)
    k = (x*inv[d])%mod
    if k+n-1 >= mod:
        return 0
    ans = fac[k+n-1]*finv[k-1]%mod
    ans *= pow(d,n,mod)
    ans %= mod
    return ans
for i in range(Q):
    x,d,n = map(int,input().split())
    print(query(x,d,n))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)

def product(m, d, n):
    if (n == 0):
        return 1
    else:
        m*=product(m + d, d, n - 1)
        return m%(10**6+3)

Q=int(input())
for i in range(Q):
    a,b,c=map(int,input().split())
    print (product(a,b,c)%(10**6+3))

Submission status: Runtime Error

Solution code:
l = raw_input().split()
Q = int(l[0])
X = []
D = []
N = []
for i in range(Q):
    l = raw_input().split()
    X.append(int(l[0]))
    D.append(int(l[1]))
    N.append(int(l[2]))

# print(Q, X, D, N)

for i in range(Q):
    x = X[i]
    d = D[i]
    n = N[i]
    cds = [0]*n
    cds[0] = 1
    cds_tmp = [0]*n
    ans = x
    # print(x, d, n)
    for j in range(1, n):
      #  print('j={}'.format(j), cds)
        cds_tmp[0] = cds[0]
        for k in range(1, j + 1):
            cds_tmp[k] += cds[k - 1] * j
            cds_tmp[k] %= 1000003
     #       print(k, cds[k - 1], cds_tmp)
        cds = [c for c in cds_tmp]
    ans = 0
    x_n = [x]*n
    for i in range(1, n):
        x_n[i] = x_n[i - 1] * x
        x_n[i] %= 1000003
    # print('x_n', x_n)
    d_n = 1
    for i in range(n):
        # print(x_n[n - i - 1], cds[i], d_n)
        ans += x_n[n - i - 1] * cds[i] * d_n
        d_n *= d
        d_n %= 1000003
        ans %= 1000003
    print(ans)

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    print(180*(n-2))
    return

#B
def B():
    s = S()
    res = 15-len(s)
    k = s.count("o")
    if k+res >= 8:
        print("YES")
    else:
        print("NO")
    return

#C
def C():
    return

#D
def D():
    n = I()
    v = [[] for i in range(n)]
    f = [[0,i] for i in range(n)]
    for i in range(n-1):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
        f[a][0] += 1
        f[b][0] += 1
    f.sort(key = lambda x:-x[0])
    s = f[0][1]
    c = LI()
    c.sort(key = lambda x:-x)
    f[0][0] = c[0]
    q = deque()
    q.append(s)
    bfs = [1 for i in range(n)]
    f.sort(key = lambda x:x[1])
    bfs[s] = 0
    k = 1
    while q:
        x = q.popleft()
        for y in v[x]:
            if bfs[y]:
                bfs[y] = 0
                f[y][0] = c[k]
                k += 1
                q.append(y)
    ans = 0
    q.append(s)
    bfs = [1 for i in range(n)]
    bfs[s] = 0
    while q:
        x = q.popleft()
        for y in v[x]:
            ans += min(f[x][0],f[y][0])
            if bfs[y]:
                bfs[y] = 0
                q.append(y)
    print(ans//2)
    for i, j in f[:-1]:
        print(i,end = " ")
    print(f[-1][0])
    return

#E
def E():
    mod = 1000003
    f = [None for i in range(mod+1)]
    f[0] = 1
    for i in range(mod):
        f[i+1] = (i+1)*f[i]%mod
    inv_f = [None for i in range(mod+1)]
    inv_f[mod] = 0
    inv_f[mod-1] = pow(f[mod-1],mod-2,mod)
    for i in range(mod-1)[::-1]:
        inv_f[i] = inv_f[i+1]*(i+1)%mod
    q = I()
    for _ in range(q):
        x,d,n = LI()
        if x == 0:
            print(0)
        elif d == 0:
            print(pow(x,n,mod))
        elif n >= mod:
            print(0)
        else:
            ans = pow(d,n,mod)
            x *= pow(d,mod-2,mod)
            x %= mod
            ans *= f[x+n-1]*inv_f[x-1]%mod
            ans %= mod
            print(ans)
    return

#F
def F():
    n = I()
    return

#Solve
if __name__ == "__main__":
    E()

Submission status: Runtime Error

Solution code:
import numpy as np
MOD = 1000003
q = int(input())
xdn = [list(map(int, input().split())) for i in range(q)]

for x in xdn:
  tmp = 1
  for l in np.linspace(x[0], x[0]+(x[2]-1)*x[1], num=x[2]).astype(np.int):
    tmp = tmp*int(l)%MOD
  print(tmp)

Submission status: Runtime Error

Solution code:
l = raw_input().split()
Q = int(l[0])
X = []
D = []
N = []
for i in range(Q):
    l = raw_input().split()
    X.append(int(l[0]))
    D.append(int(l[1]))
    N.append(int(l[2]))

# print(Q, X, D, N)

for i in range(Q):
    x = X[i]
    d = D[i]
    n = N[i]
    cds = [0]*n
    cds[0] = 1
    cds_tmp = [0]*n
    ans = x
    # print(x, d, n)
    for j in range(1, n):
      #  print('j={}'.format(j), cds)
        cds_tmp[0] = cds[0]
        for k in range(1, j + 1):
            cds_tmp[k] += cds[k - 1] * j
            cds_tmp[k] %= 1000003
     #       print(k, cds[k - 1], cds_tmp)
        cds = [c for c in cds_tmp]
    ans = 0
    for i in range(n):
        ans += x**(n - i) * cds[i] * (d**i)
        ans %= 1000003
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
Q = int(input())
mod = 1000003
frac = [1]*1000003
for i in range(2,1000003):
    frac[i] = i * frac[i-1]%mod
for _ in range(Q):
    x, d, n = map(int, sys.stdin.readline().split())
    p = pow(d, mod-2, mod)*x % mod
    if d == 0:
        print(pow(x, n, mod))
    elif x == 0:
        print(0)
    elif p == 0:
        print(0)
        continue
    elif p + n - 1 >= mod:
        print(0)
        continue
    
    print(frac[p+n-1]*pow(frac[p-1], mod-2, mod)*pow(d, n, mod)%mod)

Submission status: Runtime Error

Solution code:
import math

q = int(input())
for i in range(q):
    x, d, n = map(int, input().split())
    a = math.lgamma((x / d) + n) - math.lgamma(x / d) + n * math.log(d)
    b = int(a)
    c = a - int(a)
    ans = math.e
    for j in range(b - 1):
        ans = ans * math.e
        ans %= 1000003
    print(int(ans * (math.e ** c)))

Submission status: Runtime Error

Solution code:
#E
import sys
input=sys.stdin.readline
mod=1000003
m=mod-1
def modinv(n):
    return pow(n,mod-2,mod)
Fact=[1] #階乗
for i in range(1,m+1):
    Fact.append(Fact[i-1]*i%mod)
Finv=[0]*(m+1) #階乗の逆元
Finv[-1]=modinv(Fact[-1])
for i in range(m-1,-1,-1):
    Finv[i]=Finv[i+1]*(i+1)%mod
def comb(n,r):
    if n<r:
        return 0
    return Fact[n]*Finv[r]*Finv[n-r]%mod
q=int(input())
for _ in range(q):
    x,d,n=map(int,input().split())
    f=Fact[n]
    r=((x*modinv(d))+n-1)%mod
    c=comb(r,n)
    p=pow(d,n,mod)
    print((f*c*p)%mod)

Submission status: Runtime Error

Solution code:
import sys
import math

Q = int(input())

aaa = 1000003

for q in range(Q):
    x1, d, n = list(map(int, input().split()))

    #P = math.exp(n*math.log(d) + math.lgamma(x1/d+n)-math.lgamma(x1/d))
    P1 = math.lgamma(x1/d+n)*math.log(math.e,aaa)
    P2 = math.lgamma(x1/d)*math.log(math.e,aaa)
    P3 = math.log(math.e,aaa)

    P = (n*math.log(d,aaa)+P1-P2)

    # P =

    #P1 = math.exp(math.lgamma(x1/d+n)-math.lgamma(x1/d))
    #P1 = math.lgamma(x1/d+n)-math.lgamma(x1/d)

    #print(P)
    pp, hoge = math.modf(P)
    print(int(aaa**pp))

Submission status: Runtime Error

Solution code:
import math

mod = 1000003
LOG = math.log(mod)
q = int(input())
xdn = [list(map(int, input().split())) for i in range(q)]
for i in xdn:
    x,d,n = i[0], i[1], i[2]
    dn = pow(d,n,mod)
    child = math.lgamma(x/d + n)
    mother = math.lgamma(x/d)
    d = (child-mother) % LOG
    print(int(dn * math.exp(d)) % mod)

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
mod=1000003
m=mod-1
def modinv(n):
    return pow(n,mod-2,mod)
Fact=[1] #階乗
for i in range(1,m+1):
    Fact.append(Fact[i-1]*i%mod)
Finv=[0]*(m+1) #階乗の逆元
Finv[-1]=modinv(Fact[-1])
for i in range(m-1,-1,-1):
    Finv[i]=Finv[i+1]*(i+1)%mod
def comb(n,r):
    if n<r:
        return 0
    return Fact[n]*Finv[r]*Finv[n-r]%mod
q=int(input())
for _ in range(q):
    x,d,n=map(int,input().split())
    f=Fact[n]
    r=(x*modinv(d))%mod+n-1
    c=comb(r,n)
    p=pow(d,n,mod)
    print((f*c*p)%mod)

Submission status: Runtime Error

Solution code:
import math

Q = int(input())

mod = 10**6+3 #出力の制限

for _ in range(Q):
    a, d, n = map(int, input().split())
    ans = d ** n % mod
    ans *= math.gamma((a/d + n)%mod) % mod
    ans /= math.gamma((a/d)%mod) % mod
    print(int(ans))

Submission status: Runtime Error

Solution code:
print "9009"

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000)

Q = int(input())
XDN = [list(map(int,input().split())) for _ in range(Q)]

def kk(m,d,n,x=1):
  x*=d
  x %= mod
  m%=mod
  n%=mod
  if(d-n>=m):
    x = kk(m,d-n,n,x)%mod
  return x

mod = 1000003
for X, D, N in XDN:
  last = X+(N-1)*D
  print(kk(X, last, D))

Submission status: Runtime Error

Solution code:
import math
import numpy as np

q = int(input())

for _ in range(q):
    x, d, n = map(int, input().split())
    log = math.log(d**n) + math.lgamma(x/d+n) - math.lgamma(x/d)
    num = int(log / math.log(1000003))
    
    log -= math.log(1000003) * num
    print(int(math.exp(log)))

Submission status: Runtime Error

Solution code:
import numpy as np
MOD = 1000003
q = int(input())
xdn = [list(map(int, input().split())) for i in range(q)]

for x in xdn:
  tmp = 1
  for l in np.linspace(x[0], x[0]+(x[2]-1)*x[1], num=x[2], dtype='int'):
    tmp = tmp*int(l)%MOD
  print(tmp)

Submission status: Runtime Error

Solution code:
q = int(input())


for i in range(q):
    x,d,n = map(int, input().split())
    if n>=10**6+3:
        print(0)
        continue
    if (10**6+3-x)%d==0 and (10**6+3-x)//d < n:
        print(0)
        continue
    ans = 1
    for j in range(n):
        ans *= x+d*j
        ans %= 10**6+3
        if ans == 0:
            print(0)
            break
    print(ans)

Submission status: Runtime Error

Solution code:
import functools
import operator
q=int(input())
for i in range(q):
    x,d,n=map(int,input().split())
    a=range(x,x+d*(n-1)+1,d)
    print(functools.reduce(operator.mul,a)%1000003)

Submission status: Runtime Error

Solution code:
import numpy as np
import functools
import operator
q = int(input())
for i in range(q):
    x, d, n = map(int, input().split())
    li = np.arange(x, x+(n-1)*d+1, d)
    print(functools.reduce(operator.mul, li)%1000003)

Submission status: Runtime Error

Solution code:
from functools import reduce
from operator import mul

Q = int(input())
xdn = [[int(_) for _ in input().split()] for _ in range(Q)]

for x, d, n in xdn:
    ans = [0] * n
    for i in range(n // 2 + 1):
        ans[i] = x + (d * i)
        ans[n - i - 1] = x + (d * (n - i - 1))
    ANS = reduce(mul, ans)

    print(ANS % 1000003)

Submission status: Runtime Error

Solution code:
import numpy as np
MOD = 1000003
q = int(input())
xdn = [list(map(int, input().split())) for i in range(q)]

for x in xdn:
  tmp = 1
  for l in np.linspace(x[0], x[0]+(x[2]-1)*x[1], num=len(x)+1, dtype='int'):
    tmp = tmp*int(l)%MOD
  print(tmp)

Submission status: Runtime Error

Solution code:
import math
def keisan(x,d,n):
    c=0
    ddd=[[0]*n for _ in range(n)]
    for i in range(n):
        ddd[0][0]=x

        for k in range(i):
            if k==0:
                ddd[i][k]=(x**(i+1))%1000003
            if k==1:
                sum=(1+i)*i/2
                ddd[i][k]=(sum*d*(x**(i)))%1000003
            else:
                ddd[i][k]=((ddd[i-1][k-1]*i*d)+(ddd[i-1][k]*x))%1000003
    for sss in range(n):
        c=(c+ddd[n-1][sss])%1000003
    return(c)
Q=int(input())
ans=[]
for q in range(Q):
    A=list(map(int,input().split()))
    x=A[0]
    d=A[1]
    n=A[2]
    ans.append(keisan(x,d,n))
for x in range(Q):
    print(math.floor(ans[x]))

Submission status: Runtime Error

Solution code:
import sys
Q = int(input())
mod = 1000003
frac = [1]*1000003
for i in range(2,1000003):
    frac[i] = i * frac[i-1]%mod
for _ in range(Q):
    x, d, n = map(int, sys.stdin.readline().split())
    p = pow(d, mod-2, mod)*x % mod
    print(frac[p+n-1]*pow(frac[p-1], mod-2, mod)*pow(d, n, mod)%mod)

Submission status: Runtime Error

Solution code:
def calc(x,d,n):
    ans = [0]*n
    for i in range(n):
        if i == 0:
            ans[i] = x
        else:
            ans[i] = ans[i-1] * (x+i*d)
    return ans[n-1]%1000003
    
q = int(input())
for _ in range(q):
    x, d, n = map(int, input().split())
    print(calc(x,d,n))

Submission status: Runtime Error

Solution code:
q = int(input())
for _ in range(q):
    x, d, n = map(int, input().split())
    ans = [0]*n
    for i in range(n):
        if i == 0:
            ans[i] = x
        else:
            ans[i] = ans[i-1] * (x+i*d)
    print(ans[n-1])

Submission status: Runtime Error

Solution code:
n=int(input())
fori in range(n):
  import numpy
  a=list(map(int,input().split(" ")))
  b=[]
  for j in range(0,a[2]):
    b.append(a[0]+(j*a[1]))
   
   result=numpy.product(b)
   print(result%1000003)

Submission status: Runtime Error

Solution code:
import numpy
q=int(input())
for i in range(q):
    x,d,n=map(int,input().split())
    a=numpy.arange(x,x+d*(n-1)+1,d)
    print(a.prod()%1000003)

Submission status: Runtime Error

Solution code:
a=int(input())
i=0
soma=0
while i<a:
  x=input().split()
  x=list(map(int,x))
  a =x[0]
  q=x[1]
  n=x[2]
  if x[2]%2==1:
    m=a+(((n//2)+1)-1)*q
    soma = m*((m**2)-(q**2))
  else:
    m=(a+q)+(((((n-1)//2)+1)-1)*q)
    soma = m*((m**2)-q**2)
    soma = soma*a
  print(soma%1000003)

Submission status: Runtime Error

Solution code:
Q = int(input())

for q in range(Q):
  x,d,n = map(int, input().split())
  ret = 1
  if n % 2 == 0:
    mid = x + (int(n / 2)) * d - d / 2
  else:
    mid = x + int(n / 2) * d
  
  for i in range(int((n+1) / 2)):
    if n % 2 == 0:
      diff = d / 2
    else:
      diff = 0
    mi = d * i + diff
    
    if mi == 0:
      ret *= mid
    else:
      ret *= mid**2 - mi**2
  print(int(ret % 1000003))

Submission status: Runtime Error

Solution code:
q = int(input())
s = 1

for i in range(q) :
    x, d, n = map(int, input().split())
    ap = (range(x,x+(n-1)*d+1,d))
    for y in range(1, int(n/2)+1) :
        s *= ap[y-1]
        s *= ap[-y]
        s %= 1000003
    if n % 2 != 0 :
        s *= ap[int(n/2)]
        s %= 1000003
    print(s)
    s = 1

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000000000)


def aaa(x, d, n):
    n -= 1
    if n < 0:
        return 1
    return (x + n*d)*aaa(x, d, n)

Q = int(input())

for _ in range(Q):
    x, d, n = map(int, input().split())
    print(aaa(x, d, n)%1000003)

Submission status: Runtime Error

Solution code:
Q = int(input())

l = []
for _ in range(Q):
    x, d, n = map(int, input().split())
    l.append((x, d, n))

for x, d, n in l:
    test_div, test_mod = divmod((1000003 - x), d)
    if test_mod == 0 and test_div < d:
        print(0)
        continue
    num = 1
    for i in range(n):
        num *= divmod(x + i*d, 1000003)[1]
        num = divmod(num, 1000003)[1]
    print(num)

Submission status: Runtime Error

Solution code:
Q = int(input())

l = []
for _ in range(Q):
    x, d, n = map(int, input().split())
    l.append((x, d, n))

for x, d, n in l:
    test_div, test_mod = divmod((1000003 - x), d)
    if test_mod == 0 and test_div < d:
        print(0)
        continue
    num = 1
    for i in range(n):
        num *= divmod(x + i*d)[1]
        num = divmod(num, 1000003)[1]
    print(num)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)
q=int(input())
def product(m,d,n):
  if n==0:
    return 1
  else:
    return m*product(m+d,d,n-1)%1000003

for iii in range(q):
  x1,d1,n1=[int(_) for _ in input().split()]
  ans=product(x1,d1,n1)
  print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**9)

Q = int(input())
p = 1

def product(m, d, n):
    if (n == 0):
        return 1
    else:
        return m * product(m + d, d, n - 1)

for i in range(Q):
    x , d , n = map(int,input().split())
    print(product(x ,d ,n) % 1000003)

Submission status: Runtime Error

Solution code:
Q = int(input())

l = []
for _ in range(Q):
    x, d, n = map(int, input().split())
    l.append((x, d, n))

for x, d, n in l:
    test_div, test_mod = divmod((1000003 - x), d)
    if test_mod == 0 and test_div < d:
        print(0)
        continue
    num = 1
    for i in range(n):
        num *= x + i*d
        num = divmod(num, 1000003)[1]
    print(num)

Submission status: Runtime Error

Solution code:
import numpy as np
q = int(input())

s = 1

for i in range(q) :
    x, d, n = map(int, input().split())
    ap = np.array(range(x,x+(n-1)*d+1,d))
    for y in range(n) :
        s *= ap[y]
        s %= 1000003
    print(s)
    s = 1

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000000)

q = int(input())
x = []
d = []
n = []

def prod(m, d, n):
  if (n == 0):
    return 1
  else:
    return m * prod(m + d, d, n - 1)
  
for i in range(q):
  x1, d1, n1 =[int(j) for j in input().split()]
  p = prod(x1, d1, n1)
  p = p % 1000003
  print (p)

Submission status: Runtime Error

Solution code:
N = int(input())
XDN = []
for _ in range(N):
    XDN.append([int(i) for i in input().split()])
mod = 1_000_003
for xdn in XDN:
    ans = 1
    for i in range(xdn[2]):
        temp = (xdn[0] + i*xdn[1])%mod
        ans *= temp
    print(ans%mod)

Submission status: Runtime Error

Solution code:
q = int(raw_input())
xdn = []
for i in range(q):
    xdn.append(map(int,raw_input().split()))
ans = 1
for i in range(q):
    ans=1
    for j in range(xdn[i][2]):
        ans*=xdn[i][0]+xdn[i][1]*j
    print ans%1000003

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(1000000)


def aaa(x, d, n):
    n -= 1
    if n < 0:
        return 1
    return (x + n*d)*aaa(x, d, n)

Q = int(input())

for _ in range(Q):
    x, d, n = map(int, input().split())
    print(aaa(x, d, n)%1000003)

Submission status: Runtime Error

Solution code:
Q=int(input())
for i in range(Q):
     x, d, n = map(int, input().split())
     for j in range(n):
          m=x+d*j
          X*= m
          print(X%1000003)