Wrong Answer
Code
#include<stdio.h>
#include<stdlib.h>
int gcd(int a, int b) {
while(b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
int main() {
int n;
scanf("%d", &n);
int ar[n], res[n], i;
for(i = 0; i < n; i++) {
scanf("%d", &ar[i]);
}
for(i = 0; i < n; i++) {
res[i] = 0;
}
for(i = 1; i <= n; i++) {
int max = 0;
for(int j = 0; j < (1 << n); j++) {
int count = 0, neg = -1;
for(int k = 0; k < n; k++) {
if((j >> k) & 1) {
count++;
if(neg == -1) {
neg = ar[k];
} else {
neg = gcd(neg, ar[k]);
}
}
}
if(count == i) {
if(neg > max) {
max = neg;
}
}
}
res[i - 1] = max;
}
for(i = 0; i < n; i++) {
printf("%d ", res[i]);
}
printf("\n");
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1151 Max gcd group
- Contest
- Happy New Year 2025
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-01-02 15:59:52
- Judged At
- 2025-01-02 15:59:52
- Judged By
- Score
- 0
- Total Time
- 2ms
- Peak Memory
- 284.0 KiB