day-7-subtraction-game-theory

Problem :

Baba wants to kill Guruji. He has a master plan but Guruji is prepared for him.

Baba released a bacterial concentration of 1 unit in Guruji's underground water source on Day 0. The concentration of bacteria becomes x times the concentration day before. But,Guruji's powder kills y units of bacteria each day, starting from Day 1.

Guruji needs your help to estimate the concentration of bacteria on the N th day. 

Note : Large Input/Output Data. Use fast I/O.

Input :

First line consists of 2 space separated integers x and y. The next line consists of a single integer Q, denoting the number of queries Guruji has for you. The next Q lines are such that each line consists of a single integer N.

Output :

For each query of Guruji, print the number of bacteria present on the N th day on a new line. Since the answer can be really huge, print the answer modulo 1000000007 (10^9 + 7) .

Constraints :

2 ≤ x ≤ 100

0 ≤ y ≤ (x-2)

1 ≤ Q ≤ 10^6

1 ≤ N ≤ 10^6

Problem Setter : Sayan

Problem Tester : Sandeep , Himanshu

(By IIT Kgp HackerEarth Programming Club)

SAMPLE INPUT
5 3
3
1
3
2

SAMPLE OUTPUT
2
32
7

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
x,y=list(map(int,input().split()))
a=[1]
for i in range(1,1000001):
	value=(a[i-1]*x-y)%1000000007
	a.append(value)
Q=int(input())
for q in range(Q):
	n=int(input())
	print(a[n])


x,y=list(map(int,input().split()))
q=(int)(input())
arr=[]
arr.append(x-y)
for i in range(1,1000001):
	t=arr[i-1]*x
	arr.append((t-y)%1000000007)
for i in range(q):
	n=(int)(input())
	print(arr[n-1]%1000000007)
	




import sys
x,y=list(map(int,input().split()))
q=sys.stdin.readline()
arr=[]
arr.append(x-y)
for i in range(1,1000001):
	t=arr[i-1]*x
	arr.append((t-y)%1000000007)
for i in sys.stdin:
	n=(int)(i)
	print(arr[n-1]%1000000007)
	




import sys
x,y=list(map(int,input().split()))
q=(int)(input())
arr=[]
arr.append(x-y)
for i in range(1,1000001):
	t=arr[i-1]*x
	arr.append((t-y)%1000000007)
for i in sys.stdin:
	n=(int)(i)
	print(arr[n-1]%1000000007)