QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721455#8758. Menji 和 gcdjiangXxin#RE 0ms3704kbC++202.2kb2024-11-07 16:10:102024-11-07 16:10:11

Judging History

This is the latest submission verdict.

  • [2024-11-07 16:10:11]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3704kb
  • [2024-11-07 16:10:10]
  • Submitted

answer

// Problem: C. Modified GCD
// Contest: Codeforces - Codeforces Beta Round 67 (Div. 2)
// URL: https://codeforces.com/problemset/problem/75/C
// Memory Limit: 256 MB
// Time Limit: 2000 ms
// Author: jiangXxin
// Create Time:2024-11-06 22:35:35
// 
// Powered by CP Editor (https://cpeditor.org)

/*
   /\__/\
  (o    o)
  /      \
 // ^  ^ \\
///      \\\
  \      /
   \____/
  /\_  _/\
 */
#include<bits/stdc++.h>

#define fir first
#define sec second
#define pb push_back
#define lowbit(X) X&(-X)
#define sz(X) (int)(X).size()
#define all(X) (X).begin(),(X).end()

#define YES cout<<"YES"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define NO cout<<"NO"<<'\n'
#define No cout<<"No"<<'\n'
#define error cout<<"-1"<<'\n'
#define int long long 

using namespace std;
typedef long long unt;
typedef long double ld;
typedef vector<int> vt_int;
typedef vector<char> vt_char;
typedef vector<bool> vt_bool;
typedef vector<long long> vt_unt;
typedef vector<long double> vt_ld;
typedef vector<vector<int> > vvt_int;
typedef vector<vector<char> > vvt_char;
typedef vector<vector<bool> > vvt_bool;
typedef vector<vector<long long> > vvt_unt;
typedef vector<vector<long double> > vvt_ld;

const long long mod=1e9+7;
const long long INF=1152921504606846976;//(2^60)
const long long N=110000;

unt gcd(unt a,unt b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int L,R,pp;

bool check(int x){
	int p1=(L+x-1)/x;
	int l1=p1*x;
	int p2=R/x;
	int r1=p2*x;
	if(l1>R) return false;
	if(r1<L) return false;
	if(l1!=r1) return true;
	return false;
}

void solve(){
	cin>>L>>R;
	int d=R-L;
	pp=R-L;
	// cout<<check(1757472)<<endl;
	if((check(d))){
		cout<<d<<endl;
		return ;
	}
	if(d<=1e6){
		while(d>0){
			if(check(d)){
				cout<<d<<endl;
				return ;
			}
			d--;
		}
	}
	int p1=L/d;
	int ans=0;
	int d1=d;
	while(true){
		d1=L/p1;
		if(check(d1)){
			ans=max(ans,d1);
			break;
		}
		p1++;//p1=21,20,19,18
	}
	int p2=R/d;
	int d2=d;
	while(true){
		d2=R/p2;
		if(check(d2)){
			ans=max(ans,d2);
			break;
		}
		p2++;
	}
	cout<<ans<<endl;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int T=1;cin>>T;
	while(T--) solve();
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3704kb

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
Runtime Error

input:

6
357134483534 646200407704
504479652692 514965927651
831245941727 837097365832
778543598197 990152196633
19580905336 99295489037
228262697783 935881261360

output:

215400135901
10299318553
5813176151
198030439326

result: