题目描述
注意的地方
代码
package shulun;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class 序列的第k个数 {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static final int MOD=200907;
public static long qmi(long a,int b) {
long res=1;
while(b>0){
if((b&1)==1){
res=res*a%MOD;
}
a=(long)a*a%MOD;
b=b>>1;
}
return res%MOD;
}
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
BufferedReader bufferedReader =new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(bufferedReader.readLine());
for(int i=1;i<=t;i++){
String p[]=bufferedReader.readLine().split(" ");
int a=Integer.parseInt(p[0]);
int b=Integer.parseInt(p[1]);
int c=Integer.parseInt(p[2]);
int k=Integer.parseInt(p[3]);
if(a+c==2*b){
long res=(a+(long)(k-1)*(b-a)%MOD)%MOD;
System.out.println(res);
}else{
int q=c/b;
long ans=a*qmi(q, k-1)%MOD;
System.out.println(ans);
}
}
}
}