文章目录
R e s u l t Result Result
H y p e r l i n k Hyperlink Hyperlink
https://www.luogu.com.cn/problem/U137469?contestId=36246
D e s c r i p t i o n Description Description
T
T
T组数据,两个数
A
,
B
A,B
A,B,现在进行
K
K
K轮游戏
每一轮中小的那个乘二,大的那个减去小的那个
问 K K K轮之后较小的那个数是多少
数据范围: A , B , K ≤ 1 0 9 A,B,K\leq 10^9 A,B,K≤109
S o l u t i o n Solution Solution
我寻思着这题不是牛客一道题的弱化版吗???!!!
容易证明这个过程就是乘二mod ( A + B ) (A+B) (A+B)的过程,写个快速幂取个最小值就了啦
时间复杂度: O ( T log K ) O(T\log K) O(TlogK)
C o d e Code Code
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#define LL long long
using namespace std;LL A,B,K,P;
int T;
inline LL ksm(LL x,LL y)
{
LL res=1;
for(;y;y>>=1,(x*=x)%=P) if(y&1) (res*=x)%=P;
return res;
}
inline LL read()
{
LL d=1,f=0;char c;
while(c=getchar(),!isdigit(c)) if(c=='-') d=-1;f=(f<<3)+(f<<1)+c-48;
while(c=getchar(),isdigit(c)) f=(f<<3)+(f<<1)+c-48;
return d*f;
}
signed main()
{
T=read();
while(T--)
{
A=read();B=read();K=read();P=A+B;
printf("%lld\n",min(A*ksm(2,K)%P,B*ksm(2,K)%P));
}
}