0
Follow
0
View

# How to solve the problem of #ios#?

duwei26435753 注册会员
2023-02-27 08:23
djpraul 注册会员
2023-02-27 08:23
< div class = " md_content_show“数据- v - 3967 e397 = " " >

< div class = " aw-list-img " >

dsy_8110 注册会员
2023-02-27 08:23

0 has no natural divisible with any number
So you can decide whether ans should be 0

daiyanan6073 注册会员
2023-02-27 08:23

We need to pay attention to some boundary cases in this problem. Here is an example of code that can pass:

``````#include
using namespace std;

int gcd(int a, int b) {
if (a == 0 && b == 0) {
return 0;
} else if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}

int main() {
int a, b;
cin >> a >> b;
cout << gcd(abs(a), abs(b)); // 取绝对值
return 0;
}
``````

Explain the code: first define a function for the greatest common divisor gcd, according to the definition can be implemented. Read two integers a and b into the main function and print their greatest common divisor. Note that the input number may be negative, so you need to take the absolute value. And notice some of the boundary cases in the problem, for example, when the input is 0, the output is 0.

cymx2012 注册会员
2023-02-27 08:23
< div class = " md_content_show“数据- v - 3967 e397 = " " >

< div class = " aw-list-img " >

< div class = " aw-list-img >

cuiping3210 注册会员

Publish Time
2023-02-27 08:22
Update Time
2023-02-27 08:22