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 " > 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 " > img

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

About the Author

Question Info

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

Related Question

从itertool.combination list获取元组索引

puppeteer waitForSelector在传递字符串变量时不工作

将存储在Firebase Firestore中的文件通过Node后端发送到http端点失败

python torch

设计一个函数int stoi(char *str),将数字字符串str转换为一个整数

重定向Tomcat

Eclipse加Tomcat 导入的html加载不了css

Apache Flink: JMXReporterFactory无法找到

pytorch下基于卷积神经网络实现图像验证

tomcat在浏览器运行时报乱码