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.

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
#define mod 1000003
inline int quickpow(int base,int ind)
{
	base%=mod;
	int ans=1;
	while(ind>0)
	{
		if(ind&1)ans=ans*1ll*base%mod;
		ind>>=1;
		base=base*1ll*base%mod;
	}
	return ans;
}
inline int inv(int x)
{
	return quickpow(x,mod-2);
}
const int maxn=1e6+500;
const int N=1000002;
int fact[maxn*2],invfac[maxn];
inline int calc(int a,int b,int c)
{
	cout<<13*1ll*inv(b)%mod<<endl;
	int iv=inv(b);
	int fst=(a*1ll*iv%mod+mod-1)%mod;
	int lst=(a+(c-1)*1ll*b%mod)%mod*1ll*iv%mod;
	cout<<iv<<" "<<fst<<" "<<lst<<endl;
	cout<<fact[lst]<<" "<<invfac[fst]<<" "<<quickpow(b,c)<<endl;
	return fact[lst]*1ll*invfac[fst]%mod*1ll*quickpow(b,c)%mod;
}
int main()
{
//	cout<<93*1ll*inv(16)%mod<<endl;
	int Q,x,n,d;
	scanf("%d",&Q);
//	cout<<C<<endl;
	fact[0]=1;
	for(int i=1;i<=N;i++)
	{
		fact[i]=fact[i-1]*1ll*i%mod;
	}
	invfac[N]=inv(fact[N]);
	for(int i=N-1;i>=0;i--)
		invfac[i]=invfac[i+1]*1ll*(i+1)%mod;
	while(Q--)
	{
		scanf("%d%d%d",&x,&d,&n);
		if(d==0)
		{
			printf("%d\n",quickpow(x,n));
			continue;
		}
		if(n>=mod)
		{
			printf("0\n");
			continue;
		}
		printf("%d\n",calc(x,d,n));
	}
	return 0;
}