#29561: C++紀錄


e3524167 (Kenlogin)

School : No School
ID : 186743
IP address : [182.233.207.92]
Last Login :
2022-03-17 21:12:56
a024. 最大公因數(GCD) | From: [182.233.207.92] | Post Date : 2022-03-12 03:33

#include <iostream>

#include <string> 

#include <sstream>

using namespace std;

int gcd(int, int);

int main()

{

int a = 0;

int b = 0;

 

while (cin >> a >> b)

{

cout << gcd(a, b) << endl;

}

}

 

int gcd(int a,int b) 

{

int r = 0;

while (b != 0)

{

r = a % b;

a = b;

b = r;

}

return a;

}

 
ZeroJudge Forum