题目描述
算是再熟悉一遍快速幂,
快速幂步骤
- 初始化res=1
- while(k)
- 如果k最后一位是1,res*a
- a每次*a (每次都要平方)
- k>>1
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int M=200907;
int n;
ll qmi(ll start,ll a,ll k,ll q)
{
ll res=start;
while(k)
{
if(k&1)
{
res=(ll)res*a%q;
}
a=(ll)a*a%q;
k=k>>1;
}
return res;
}
int main()
{
cin>>n;
while(n--)
{
int a,b,c,k;
cin>>a>>b>>c>>k;
ll res;
if(b-a == c-b)
{
ll d=b-a;
res=(a+(k-1)*d)%M;
}
else
{
ll q=b/a;
res=qmi(a,q,k-1,M);
}
cout<<res<<endl;
}
return 0;
}
兄弟有时间填个邀请码hhhhhhhhh(可以得AC币,邀请码在学生认证那填) 我的邀请码是:GUDFH