题解:P11275 微观戏剧
当
由于两个数之间的连边长度为它们的最小公倍数,而
当
如果
- 直接从
x 走到y 。 - 从
x 出发,经过若干个“中转点”,再走到y 。
前者的路径长度为
当
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
int t;cin>>t;while(t--){
int x,y;cin>>x>>y;
int a=__gcd(x,y);
if(x==y)cout<<0<<endl;
else if(a==x)cout<<y<<endl;
else if(a==y)cout<<x<<endl;
else cout<<x+y<<endl;
}
return 0;
}