公式:p+q-GCD(q,p)

具体分析:

http://www.shuxueweb.com/shuxuebolan/qiuti/shuxuebolan_9112.html

#include<iostream>
using namespace std;
int hcf(int a,int b)
{
    int r=0;
    while(b!=0)
        {
        r=a%b;
        a=b;
        b=r;
        }
    return(a);
} 
int main()
{
	int q,p;
	while(cin>>q>>p)
	{
		cout<<q+p-hcf(q,p)<<endl;
	}
	return 0;
}

相关文章:

  • 2021-11-07
  • 2021-10-15
  • 2022-12-23
  • 2021-07-15
  • 2022-02-23
  • 2022-12-23
  • 2021-12-05
  • 2021-12-25
猜你喜欢
  • 2021-09-02
  • 2021-06-05
  • 2021-05-19
  • 2022-12-23
  • 2021-07-02
  • 2022-02-03
  • 2022-02-16
相关资源
相似解决方案