-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy path1051 B. Relatively Prime Pairs.cpp
49 lines (48 loc) · 1.11 KB
/
1051 B. Relatively Prime Pairs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
using namespace std;
int main()
{
fastread();
//freopen("input.txt","r", stdin);
ll n, l, r,gcd = 0, a, b;
cin>>l>>r;
a = l, b = r;
n = (r - l +1) / 2;
vector< pair<ll,ll> >v;
for(ll i=0; i<n; i++){
v.pb(make_pair(a++,b--));
}
for(ll i=0; i<n; i++){
gcd = __gcd(v[i].first,v[i].second);
if(gcd > 1){
if(i+1 < n){
swap(v[i].first,v[i+1].second);
}
}
}
bool ok = false;
for(ll i=0; i<n; i++){
gcd = __gcd(v[i].first,v[i].second);
if(gcd == 1){
ok = true;
}
else{
ok = false;
break;
}
}
if(ok){
cout<<"YES\n";
for(ll i=0; i<n; i++){
cout<<v[i].first<<" "<<v[i].second<<endl;
}
}
else{
cout<<"NO\n";
}
return 0;
}