尝试做最大违约数的非法指令(核心弃权)

时间:2018-10-12 22:00:23

标签: c++

帮助,当我在执行代码后在终端中引入161043216时:

#include <iostream>
using namespace std;

int main () {

    int a, b;
    cin >> a >> b;
    int r=0;

    int i=0;
    while (i<a and i<b) {
        if (a%i==0 and b%i==0) r=i;
        i++;
    }

    cout << "El mcd de " << a << " i " << b << " es " << r << "." << endl;
}

然后按Enter,它显示“非法指令(核心已转储)”。

1 个答案:

答案 0 :(得分:-2)

解决方案:

#include <iostream>

using namespace std;

int main () {
int a, b;
cin >> a >> b;
int r=0;

int i=1;
while (i<=a and i<=b) {
    if (a%i==0 and b%i==0) r=i;
    i++;
}

cout << "El mcd de " << a << " i " << b << " es " << r << "." << endl;
}

我已修复错误,谢谢大家:)