Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок+ 2
Regarding finding largest gcd among given n numbers
Problem Statement : You are given an array of n positive integers. Your task is to find two integers such that their greatest common divisor is as large as possible. Input The first input line has an integer n : the size of the array. The second line has n integers x1,x2,…,xn : the contents of the array. Output Print the maximum greatest common divisor. My question is , what mistakes am I making in the logic to the program. Please help me find it out and fix the code . https://code.sololearn.com/c9W4B6G7Wnfk/?ref=app
2 ответов
+ 6
Try inserting some diagnostics after line 42.
cout << "divisors: ";
for(int i = 0;i <a[n-1]+1 ;++i) {
cout << i << " " << divisors[i] << endl;
}
You will see that your divisor array is full of garbage values. You should initialize your array with 0s I think (although I don't completely understand how your algorithm is supposed to work).
+ 3
Tibor Santa yeah thanks sir I got that point just a few minutes ago 😄