Baba & Guruji
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 xtimes 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
-
#include<iostream>
-
#include<cstdio>
-
#include<string>
-
#define ull long long int
-
using namespace std;
-
#define max 1000001
-
#define mod 1000000007
-
ull conc[max];
-
void pre(int x,int y)
-
{
-
conc[0]=1;
-
for(int i=1;i<max;i++)
-
{
-
conc[i]=(conc[i-1]*x)%mod-y;
-
}
-
}
-
int main()
-
{
-
int x,y;
-
int Q,N;
-
scanf("%d",&x);
-
scanf("%d",&y);
-
scanf("%d",&Q);
-
pre(x,y);
-
for(int j=0;j<Q;j++)
-
{
-
scanf("%d",&N);
-
printf("%d\n",conc[N]%mod);
-
}
-
}
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 xtimes 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
- #include<iostream>
- #include<cstdio>
- #include<string>
- #define ull long long int
- using namespace std;
- #define max 1000001
- #define mod 1000000007
- ull conc[max];
- void pre(int x,int y)
- {
- conc[0]=1;
- for(int i=1;i<max;i++)
- {
- conc[i]=(conc[i-1]*x)%mod-y;
- }
- }
- int main()
- {
- int x,y;
- int Q,N;
- scanf("%d",&x);
- scanf("%d",&y);
- scanf("%d",&Q);
- pre(x,y);
- for(int j=0;j<Q;j++)
- {
- scanf("%d",&N);
- printf("%d\n",conc[N]%mod);
- }
- }
No comments:
Post a Comment