-->
当前位置:首页 > 题库

PROGRAMMING:greatest common divisor

Luz5年前 (2021-05-10)题库397
#####Problem description
Given two positive integers, find their greatest common divisor.
#####Enter a description
Enter a line containing two positive integers (< 1000000000).
#####Output description
Output a positive integer, that is, the greatest common divisor of the two positive integers.
#####Sample input
```in
6 9
```
#####Sample output
```out
three
```
#####Tips
The greatest common divisor can be obtained by division
Suppose a > b > 0, then the greatest common divisor of a and B is equal to the greatest common divisor of B and a% B, and then the problem becomes to solve the greatest common divisor of B and a% B.
Because this process will continue to decrease until a% B equals 0, the value of B is the required greatest common divisor.
For example:
The greatest common divisor of 9 and 6 is equal to the greatest common divisor of 6 and 9% 6 = 3.
Since 6% 3 = = 0, the greatest common divisor is 3< br>





answer:If there is no answer, please comment