题目大意
有T行,每行有三个整数 ,,,每次 可变为 当 时停止操作,求过程中 的最小值。
优化
当 时,每次可变为 ,所以加一个特判。
当 时,不会发生这种问题。
特别的,不加特判会被这个数据卡爆,只能拿部分分,会TLE三个点。
if(a==1){
if(b!=0){
x%=b;
x-=b;
}
}AC code
#include <bits/stdc++.h>
using namespace std;
#define int __int128
#define QAQ ch=getchar();
#define qaq printf("\n")
namespace quickread{
inline int read(){
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if(ch=='-')f=-1;QAQ}
while (ch>='0'&&ch<='9'){x=x*10+ch-'0';QAQ}
return x*f;
}
inline void write(int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
}
using namespace quickread;
int n,a,x,b;
signed main(){
n=read();
while(n--){
x=read(),a=read(),b=read();
if(a==1){
if(b!=0){
x%=b;
x-=b;
}
}
else while(a*x-b<x&&x>=0) x=x*a-b;
write(x),qaq;
}
return 0;
}