[P14079]最短距离-题解
Update on
修复了 LaTeX 问题。
本题需要分类讨论,共 3 种情况:
1.
2.
3.一定不要忘了
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,p,q;
cin>>n>>p>>q;
while(n--)
{
int a,b;
cin>>a>>b;
if(a==b)
{
cout<<0<<endl;
continue;
}
if(__gcd(a,b)==1)
{
if(a==1||b==1)
{
cout<<p<<endl;
}
else
{
cout<<min(p,2*q)<<endl;
}
}
else
{
cout<<min(q,2*p)<<endl;
}
}
return 0;
}