You are viewing a single comment's thread. Return to all comments →
C solution
int t; scanf("%d", &t); while(t--){ int a_count; scanf("%d", &a_count); int a[a_count]; for(int j = 0 ; j < a_count ; j++){ scanf("%d", &a[j]); } int gcd[a_count+1]; int result_count = 0; gcd[result_count++] = a[0]; for(int i = 0 ; i < a_count-1 ; i++){ int y = a[i]; while(y % a[i+1] != 0 || (y % a[i] != 0 && a[i] % y != 0)){ y++; } gcd[result_count++] = y; } gcd[result_count++] = a[a_count-1]; for(int i = 0 ; i <= a_count ; i++){ printf("%d ", gcd[i]); } printf("\n"); }
Seems like cookies are disabled on this browser, please enable them to open this website
John and GCD list
You are viewing a single comment's thread. Return to all comments →
C solution