-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoj1442.cpp
More file actions
49 lines (45 loc) · 758 Bytes
/
oj1442.cpp
File metadata and controls
49 lines (45 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdio.h>
int n,k;
long long buf[3];
long long arith(long long a,long long b,int k){
long long ans=a;
while(k){
if(k%2){
ans+=b;
ans%=200907;
}
k/=2;
b+=b;
b%=200907;
}
return ans;
}
long long geo(long long a,long long b,int k){
long long ans=a;
while(k){
if(k%2){
ans*=b;
ans%=200907;
}
k/=2;
b*=b;
b%=200907;
}
return ans;
}
int main(){
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++){
for(int j=0;j<3;j++)
scanf("%lld",&buf[j]);
scanf("%d",&k);
long long ans;
if(buf[2]-buf[1]==buf[1]-buf[0])
ans=arith(buf[0],buf[1]-buf[0],k-1);
else
ans=geo(buf[0],buf[1]/buf[0],k-1);
printf("%lld\n",ans);
}
}
return 0;
}