辗转相除法求两个数是否互素

来源:互联网 发布:js字符串数字相加 编辑:程序博客网 时间:2024/05/16 18:28
#include <iostream>using namespace std;int gcd(int x,int y);void main(){int x,y;cin>>x>>y;if(gcd(x,y)==1)cout<<"互素!"<<endl;else cout<<"不互素!"<<endl;}//版本一int gcd(int x,int y){int c;do{c = x % y;x = y;y = c;}while (c);if(x==1)return 1;else return 0;}//版本二//int gcd(int a,int b)//{//if(b==0)return a; //else return gcd(b,a%b); //} //递归法求最大公约数,当最大公约数是1的时候,两个数互素

0 0
原创粉丝点击