My issue
Where I have to change my code
My code
#include <stdio.h>
// Function to compute the GCD of two numbers
long long gcd(long long a, long long b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
// Function to determine if all elements of the array can be made equal
void canMakeEqual(int n, long long arr[]) {
long long resultGCD = arr[0];
int hasZero = 0;
// Check if there's a zero in the array and calculate the GCD of all elements
for (int i = 0; i < n; i++) {
if (arr[i] == 0) {
hasZero = 1;
}
if (i > 0) {
resultGCD = gcd(resultGCD, arr[i]);
}
}
// If there's a zero in the array, it's always possible to make all elements equal to zero
if (hasZero) {
printf("YES\n");
} else if (resultGCD > 1) {
printf("YES\n");
} else {
printf("NO\n");
}
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
int N;
scanf("%d", &N);
long long arr[N];
for (int i = 0; i < N; i++) {
scanf("%lld", &arr[i]);
}
canMakeEqual(N, arr);
}
return 0;
}
Problem Link: Make My Array Equal Practice Coding Problem