求最大公约数,及最小公倍数。

来源:互联网 发布:福建晨曦软件下载 编辑:程序博客网 时间:2024/06/05 00:47

#include<iostream>
using namespace std;
#include <iostream>
using namespace std;
int gcd(int a,int b)
{
 int r=a%b;
 while (r!=0)
 {
  a=b;
  b=r;
  r=a%b;
 }                        //最小公倍数= ( m*n)/ gcd(m,n)
 return b;
}


int main()
{
 int m,n;
 while(cin>>m>>n)
 {
  if(gcd(m,n)==1)
  {
   cout<<"yes"<<endl;
  }
  else
   cout<<"no"<<endl;
 }


 return 0;
}

0 0
原创粉丝点击