import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y =sc.nextInt();
import java.util.Scanner;
/**
* @author Allen_Hua
* @create_time 创建时间:May 13, 2018 1:45:43 PM 类说明
*/
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
while (scan.hasNext()) {
int a = scan.nextInt();
int b = scan.nextInt();
System.out.println(gcd(a, b));
}
}
//辗转相除法求最大公约数 greatest common divisor
private static int gcd(int a, int b) {
// TODO Auto-generated method stub
int max, min, temp;
//将a、b中的较大值给max 较小值给min
if (a > b) {
max = a;
min = b;
} else {
min = a;
max = b;
}
temp = max % min;//大值对小值取模
while (temp != 0) {
max = min;
min = temp;
temp = max % min;
}
return min;
}
}
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
int GCD(int a, int b)
{
if (b == 0)
{
return a;
}
else
{
return GCD(b, a % b);
}
}
int main()
{
int a, b;
while (cin >> a >> b)
{
cout << GCD(a, b) << endl;
}
return EXIT_SUCCESS;
} #include <iostream>
(720)#include <algorithm>
using namespace std;
int main() {
int a, b;
while (cin >> a >> b) {
cout << __gcd(a, b) << endl;
}
return 0;
}
algorithm头文件里有已经写好的最大公因数的函数😉
//辗转相除法
#include<iostream>
using namespace std;
int zdgy(int a,int b){
while(a%b!=0){
a=a-a/b*b;
int temp=a;
a=b;
b=temp;
}
return b;
}
int main(){
int m,n;
while(cin>>m>>n){
if(m>n)
cout<<zdgy(m,n)<<endl;
else
cout<<zdgy(n,m)<<endl;
}
return 0;
} #include<bits/stdc++.h>
int max(int m,int n){
if(n==0)
return m;
else
return max(n,m%n);
}
int main(){
int m,n;
while(scanf("%d %d",&m,&n)!=EOF)
printf("%d\n",max(m,n));
return 0;
}//欧几里得算法的递归形式
------------------------------------------------------------------------------
#include<bits/stdc++.h>
int main(){
int m,n,t;
while(scanf("%d %d",&m,&n)!=EOF){
while(n!=0){
t=m%n;
m=n;
n=t;
}
printf("%d\n",m);
}
return 0;
}//欧几里得算法的非递归形式 #include<iostream>
using namespace std;
int main(){
int a,b;
while(cin>>a>>b){
int result=1;
for(int i=2;i<=a&&i<=b;i++){
if(a%i==0&&b%i==0){
result*=i;
a=a/i;
b=b/i;
i=2;
}
}
cout<<result<<endl;
}
return 0;
}
#include<iostream>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b); }
int main(){
int a,b;
while(cin>>a>>b)cout << gcd(a, b) << endl;
return 0;
}
短小的我嘻嘻
import java.util.Scanner;
public class Main{
public static int gcd(int a, int b){
if(b==0)
return a;
return gcd(b, a%b);
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
System.out.println(gcd(in.nextInt(), in.nextInt()));
}
}
}
简介代码,看着清爽
package com.speical.first;
import java.util.Scanner;
/**
*
* @author special
* @date 2018年1月30日 上午10:44:58
*/
public class Pro158 {
public static int GCD(int a, int b){
return a % b == 0 ? b : GCD(b, a % b);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
while(input.hasNext()){
System.out.println(GCD(input.nextInt(), input.nextInt()));
}
}
}