QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#628599 | #8758. Menji 和 gcd | jack | WA | 123ms | 3632kb | C++14 | 1.2kb | 2024-10-10 21:09:22 | 2024-10-10 21:09:29 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll L,R;
bool check(ll u)
{
ll f;
if(L%u==0)
{
f=L/u;
}else f=L/u+1;
ll s=f*u;
if(R-s>=u) return true;
else return false;
}
void solve()
{
cin>>L>>R;
ll ans=0;
// for(ll i=7007007007-;i<=7007007007;i++)
// {
// cout<<check(i)<<endl;
// }
for(ll l=1,r;l<=L;l=r+1)
{
r=L/(L/l);//定义右边界
if(check(l)==0&&check(r)==0) continue;
if(check(l))
{
ll l1=l,r1=r;
while(l1<r1)
{
ll mid=l1+r1+1>>1;
if(check(mid)) l1=mid;
else r1=mid-1;
}
ans=max(ans,l1);
}else
{
ll l1=l,r1=r;
while(l1<r1)
{
ll mid=l1+r1+1>>1;
if(!check(mid)) l1=mid;
else r1=mid-1;
}
ans=max(ans,l1+1);
}
if(check(r)) ans=max(ans,r);
}
//cout<<check(129)<<endl;
cout<<ans<<'\n';
}
int main()
{
int t;
cin>>t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 20ms
memory: 3632kb
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: 123ms
memory: 3560kb
input:
6 357134483534 646200407704 504479652692 514965927651 831245941727 837097365832 778543598197 990152196633 19580905336 99295489037 228262697783 935881261360
output:
215400135901 10299318553 5813176151 198030439326 19580905336 228262697783
result:
wrong answer 5th numbers differ - expected: '49647744518', found: '19580905336'