panda-and-chain-reaction

Panda has become a scientist recently. In his laboratory, there are infinite number of chambers where a chamber number K is connected to a chamber number K-1.  

The numbering of chambers start from 0. Initially, X number of particles are present in the chamber number 0. The number of particles present in chamber K is K times the number of particles present in chamber K-1.   You are supposed to help Panda in finding out the number of particles in a given chamber number N.  

Note: The number of particles in chamber K cannot be calculated until the number of particles in chamber K-1 are calculated.  

Input Format:

The first line will contain the integer T, the number of test cases. Each test case consists of two space separated integers N and X.   

Output Format:

For each test case, output the answer to Panda's query. Since the output can be very large, output the answer modulo 10^6+3.  

Constraints:

1 ≤ T ≤ 10^5

Subtask 1: (20 points)
1 ≤ N, X ≤ 10^5

Subtask 2: (80 points)
1 ≤ N, X ≤ 10^18SAMPLE INPUT
2
1 3
2 1

SAMPLE OUTPUT
3
2

Explanation

Case 1: For first test case, initially there were 3 particles. 
In Chamber K=1, the number of particles became 1*3 = 3.

Case 2: Initially, there is only 1 particle.
In Chamber K=1, the number of particle became 1*1 = 1.
In Chamber K=2, the number of particle became 2*1 = 2.

Difficulty: EASY
Tags: Number theory

Fundamentals

Ad-hoc

Starter code:

Solutions:
'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import math

t=int(input())
fac_arr=[0]*1000013
fac_arr[0]=1
#print t
for i in range(1,1000013):
	fac_arr[i] = fac_arr[i-1] * i	
	fac_arr[i] = fac_arr[i]%1000003
	
for i in range(t):
	ch, pa = list(map(int, input().split()))
	if ch > 1000013:
		print(0)
	else:
		cal = pa%1000013
		cal = cal * fac_arr[ch]
		cal = cal % 1000003
		print(cal)





modulo = pow(10,6)+3
f = [1,1]
for i in range(2,modulo+1):
	f.append( ( i*f[i-1] ) % modulo )
tc = int(input())
for i in range(tc):
	k,x = list(map(int,input().split()))
	if k>modulo:
		k=modulo
	x = x % modulo
	print((x*f[k] % modulo))
	


MOD = (10**6 + 3)
fact = [1, 1]
for index in range(2, MOD + 1):
	fact.append((fact[index -1] * index) % MOD)
for _ in range(eval(input())):
	N, x = list(map(int, input().split()))
	if N > MOD:
		N = MOD
	x = x % MOD
	print(((fact[N] * x) % MOD))


t=eval(input())
l=[1,2]
mod=10**6+3
for i in range(3,mod):
	l.append(((i%mod)*(l[-1]%mod))%mod)

for _ in range(t):
	n,x=list(map(int,input().split()))
	if n>(10**6+2):
		print(0)
	else:
		print((((x%mod)*(l[n-1]%mod))%mod))


t=eval(input())
arr=[1]*1000004
for i in range(1,1000004):
	arr[i]=(i*arr[i-1])%1000003
while t:
	t-=1
	n,p=list(map(int,input().split()))
	if n>1000003:
		print('0')
	else:
		print((arr[n]*p)%1000003)


modulo = pow(10,6)+3
f = [1,1]
for i in range(2,modulo+1):
	f.append( ( i*f[i-1] ) % modulo )
tc = int(input())
for i in range(tc):
	k,x = list(map(int,input().split()))
	if k>modulo:
		k=modulo
	x = x % modulo
	print((x*f[k] % modulo))
	


numOfInput = int(input())
mod = 10**6 + 3

cache = {}
cache[0] = 1
for x in range(1, mod + 1):
	cache[x] = (cache[x-1] * x) % mod


def find_par_in_cham(cham, par_val):
	po = par_val % mod
	if (cham > mod):
		cham = mod
	fac = cache[cham] % mod
	return (po * fac) % mod


for x in range(numOfInput):
	vallist = list(map(int, input().split(" ")))
	print(find_par_in_cham(vallist[0], vallist[1]))


mod = 1000003
a =[]
a.append(1)
for x in range(1,1000004):
	a.append(x*a[x-1])
	a[x] = a[x]%mod
t=eval(input())

while(t>0):
	n, x = [int(y) for y in input().split()]
	x = x%mod
	if(n>mod):
		print("0")
	
	else:
	    cal = a[n]*x
	    cal = cal%mod
	    print(cal)
	t=t-1


mod=10**6+3
past_fact=[1]
def fact():
	prod=1
	i=1
	while i<1000003:
		prod=(prod*i)%mod
		past_fact.append(prod)
		i+=1
		
fact()
for _ in range(eval(input())):
	n,x=list(map(int,input().split()))
	
	i=1
	x=x%mod
	
	if n>=mod:
		print(0)
	else:
		#print "HERE"
		print((past_fact[n]*x)%mod)


t = int(input())
factorial = [1,1,2,6,24,120,720]
while (t>0):
    
	str = input().split(' ')
	n = int(str[0])
	x = int(str[1])
	ans = 0
	fact = 1
	if n<1000003:
		if n<len(factorial):
			fact = factorial[n]
		else:
			i = len(factorial)-1
			fact = factorial[i]
			i+=1
			while i<=n:
				fact = (fact*i)%1000003
				factorial.append(fact)
				i+=1
		ans = (fact*x)%1000003;
	print(ans)
	t-=1;
	


modulo = pow(10,6)+3
f = [1,1]
for i in range(2,modulo+1):
	f.append( ( i*f[i-1] ) % modulo )
tc = int(input())
for i in range(tc):
	k,x = list(map(int,input().split()))
	if k>modulo:
		k=modulo
	x = x % modulo
	print((x*f[k] % modulo))
	


import sys
from math import log
def order_size(order):
	if order <= 0: return 0
	return int(log(order, 10) + 1)
_FAC_TABLE = [1, 1]
def fact(n):
	if n < len(_FAC_TABLE):
		return _FAC_TABLE[n]
	last = len(_FAC_TABLE) - 1
	total = _FAC_TABLE[last]
	i = last + 1
	while i <= n:
		total = total*i%1000003
		_FAC_TABLE.append(total)
		i+=1
	return total
t=int(sys.stdin.readline().strip())
while t>0:
	n,k=list(map(int,sys.stdin.readline().strip().split(' ')))
	if order_size(n)<=6 and order_size(k)<=6: print((fact(n)*k%1000003))
	else: print((0))
	t-=1