/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 0ms 284.0 KiB
#2 Wrong Answer 21ms 464.0 KiB
#3 Wrong Answer 106ms 460.0 KiB

Code

#include <stdio.h>
#include <string.h>

int gcd(int a, int b){
    if(a>b){
        int temp = a;
        a = b;
        b = temp;
    }
    int i;
    for(int n=1; n<=a; n++){
        i = a/n;
        if(a%i==0 && b%i==0) return i;
    }
}

int main() {
    int t;
    scanf("%d",&t);
    
    while(t--){
        int n, combs=1;
        scanf("%d",&n);
        int arr[n],count[n];
        for(int i=0; i<n; i++) scanf("%d", &arr[i]);
        
        for(int i=0; i<n; i++){
            combs = 2*combs;
            count[i] = 0;
        }
            
        combs-=1;
        int mat[n][combs];
        
        while(combs){
            int temp = combs,index = n-1,mat_ind = -1, gcd_G;
            while(temp!=0){
                if(temp%2==1){
                    if(mat_ind==-1) gcd_G = arr[index];
                    else gcd_G = gcd(gcd_G, arr[index]);
                    mat_ind++;
                }
                temp = temp/2;
                index--;
            }
            count[mat_ind]++;
            mat[mat_ind][count[mat_ind]-1] = gcd_G;
            combs--;
        }
        
        int result = 1;
        for(int i=0; i<n; i++){
            int sum = 0;
            for(int j=0; j<count[i]; j++){
                sum+=mat[i][j];
            }
            result*=sum;
        }
        
        printf("%d\n", result);
    }
  
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1105 Ohh that gcd again
Language
C99 (GCC 13.2.0)
Submit At
2025-09-04 12:56:26
Judged At
2025-09-04 22:38:55
Judged By
Score
10
Total Time
106ms
Peak Memory
464.0 KiB