莫欺少年穷,修魔之旅在这开始—>算法提高课题解
结论: $只有\ a=b=c\ 时,才会既是等差数列又是等比数列$
证明:
$\begin{cases}2b=a+c\\\\b^2=ac\end{cases}\Rightarrow ac=(\dfrac{a+c}{2})^2\Rightarrow(a-c)^2=0\Rightarrow a=c\Rightarrow 即\ a=b=c$
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 200907;
int qmi(int a,int b)
{
int res=1;
while(b)
{
if(b&1) res=(LL)res*a%mod;
a=(LL)a*a%mod;
b>>=1;
}
return res;
}
int main()
{
int T;
cin>>T;
while(T--)
{
int a,b,c,k;
cin>>a>>b>>c>>k;
//等差数列
if(a+c==b*2) cout<<(a+(LL)(b-a)*(k-1))%mod<<endl;
//等比数列
else cout<<((LL)a*qmi(b/a,k-1))%mod<<endl;
}
return 0;
}