昨天 ARC B 题
  • 板块学术版
  • 楼主EEchoyukii
  • 当前回复0
  • 已保存回复0
  • 发布时间2022/10/10 21:28
  • 上次更新2023/10/27 07:56:47
查看原帖
昨天 ARC B 题
212833
EEchoyukii楼主2022/10/10 21:28

这么写为啥会 WA on 24(最后一个点)啊

求个神教教 /kel

#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
#define int long long 
inline int read(){
	register int x=0,f=0,ch=getchar();
	while('0'>ch||ch>'9')f^=ch=='-',ch=getchar();
	while('0'<=ch&&ch<='9')x=x*10+(ch^'0'),ch=getchar();
	return f?-x:x;
}

signed main(){
	int Test=read();
	while(Test--) {
		int a,b;
		a=read(),b=read();
		if(a >= b) {
			printf("%lld\n", a-b);
		}else {
			int ans = a + b;
			int l = 1,r;
			while(l <= b - 1) {
				r = (b - 1) / ((b - 1) / l);
				int x = max( (b-1) / r + 1 - a , 0ll );
				int y = l * (a + x) - b;
				ans = min(ans, x + y);
				l = r + 1;
			}
			printf("%lld\n", ans);
		}
	}
	return 0;
}



2022/10/10 21:28
加载中...