QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#661179 | #8758. Menji 和 gcd | qdsdsy# | WA | 0ms | 1948kb | C++20 | 935b | 2024-10-20 15:02:21 | 2024-10-20 15:02:21 |
Judging History
answer
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;
bool check(ll L,ll R,ll ans){
return (1+(L%ans!=0))*ans-L%ans<=(R-L);
}
void solve()
{
ll L,R;
scanf("%lld%lld",&L,&R);
if(R-L>=L){
printf("%lld\n",R/2);
return;
}
for(int x=1;x<=(int)sqrt(L);x++){
ll l=(L+x)/(x+1),r=L/x;
// if(l<=145 && r>=145)
// int i=1;
if(r*x==L){
if(check(L,R,r)){
printf("%lld\n",r);
return;
}
r--;
}
if(l*(x+1)==L){
if(check(L,R,l)){
printf("%lld\n",l);
return;
}
l++;
}
if(l>r) continue;
ll now=2*l-L%l;
long double t=1.0*(R-L-now)/(x+2);
if(t>=0){
printf("%lld\n",(ll)floor(l+t));
return;
}
}
ll ans=L/((ll)sqrt(L))+1;
while(ans>=(R-L)/2){
if(check(L,R,ans)){
printf("%lld\n",ans);
return;
}
ans--;
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 1940kb
input:
10 1 2 2 4 6 10 11 21 147 154 1470 1540 2890 3028 998244353 1000000007 34827364537 41029384775 147147147147 154154154154
output:
1 2 3 7 7 70 126 1754385 5861340682 7007007007
result:
ok 10 numbers
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 1948kb
input:
6 357134483534 646200407704 504479652692 514965927651 831245941727 837097365832 778543598197 990152196633 19580905336 99295489037 228262697783 935881261360
output:
178567241767 10299318553 5813176151 198030439326 49647744518 467940630680
result:
wrong answer 1st numbers differ - expected: '215400135901', found: '178567241767'