Language: C++

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdbool.h>

int64_t extGCD(int64_t a, int64_t b, int64_t *x, int64_t *y) {
    if (b == 0) {
        *x = 1;
        *y = 0;
        return a;
    }
    int64_t d = extGCD(b, a%b, y, x);
    (*y) -= a/b * (*x);
    return d;
}

uint64_t invmod(uint64_t x, uint64_t p)
{
	int64_t r, s;
	if(extGCD(x, p, &r, &s)!=1){
		printf("ERR\n");
		abort();
	};
	return (r + p) % p;
}

#define VLIST_MIN 100000
typedef uint64_t vlist_element_type;

typedef struct {
    int size, asize;
    vlist_element_type *a;
} vlist;

vlist *vlist_init()
{
    vlist *vl = malloc(sizeof(vlist));
    vl->size = 0;
    vl->asize = VLIST_MIN;
    vl->a = malloc(sizeof(vlist_element_type) * vl->asize);
    return vl;
}

void vlist_add(vlist *vl, vlist_element_type x)
{
    if(vl->size == vl->asize){
        vl->asize *= 2;
        vl->a = realloc(vl->a, sizeof(vlist_element_type) * vl->asize);
    }
    vl->a[vl->size] = x;
    vl->size++;
}

void vlist_term(vlist *vl)
{
    free(vl->a);
    free(vl);
}

vlist *prime_list(uint64_t x)
{
    bool *nl = malloc(sizeof(int) * (x+1));

    nl[0] = nl[1] = false;
    for(int i=2; i<(x+1); i++){
        nl[i] = true;
    }

    for(int i=2; i*i<x; i++){
        if(nl[i]==true){
            for(int j=2 ;i*j<=x; j++){
                nl[i*j] = false;
            }
        }
    }

    vlist *p = vlist_init();
    for(int i=0; i<x+1; i++){
        if(nl[i] == true){
            vlist_add(p, i);
        }
    }

    free(nl);
    return p;
}

vlist *prime_factorize(uint64_t x, vlist *p)
{
    vlist *q = vlist_init();
    for(int i=0; i<p->size; i++){
        int qi;
        for(qi=0; x%p->a[i]==0; x/=p->a[i], qi++);
        vlist_add(q, qi);
    }
    return q;
}

void prime_lcm(vlist *r, vlist *q1, vlist *q2)
{
    for(int i=0; i<r->size; i++){
        r->a[i] = q1->a[i] > q2->a[i] ? q1->a[i] : q2->a[i];
    }
}

int main()
{
    int N;
    scanf("%d", &N);

    uint64_t P = 1000000007;

    vlist *p = prime_list(1000000);
    int *A = malloc(sizeof(int) * N);
    vlist *qi = prime_factorize(1, p);

    for(int ni=0; ni<N; ni++){
        scanf("%d", A+ni);
        vlist *q = prime_factorize(A[ni], p);
        prime_lcm(qi, q, qi);
    }

    uint64_t mprod = 1;
    for(int i=0; i<qi->size; i++){
        for(int j=0; j<qi->a[i]; j++){
            mprod *= p->a[i];
            mprod %= P;
        }
    }

    uint64_t res = 0;
    for(int ni=0; ni<N; ni++){
        res += mprod * invmod(A[ni], P);
        res %= P;
    }

    printf("%"PRIu64"\n", res);

    return 0;
}



Compiler output:
a.cc:138:12: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
  138 |     printf("%"PRIu64"\n", res);
      |            ^
a.cc: In function 'vlist* vlist_init()':
a.cc:38:23: error: invalid conversion from 'void*' to 'vlist*' [-fpermissive]
   38 |     vlist *vl = malloc(sizeof(vlist));
      |                 ~~~~~~^~~~~~~~~~~~~~~
      |                       |
      |                       void*
a.cc:41:19: error: invalid conversion from 'void*' to 'vlist_element_type*' {aka 'long unsigned int*'} [-fpermissive]
   41 |     vl->a = malloc(sizeof(vlist_element_type) * vl->asize);
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                   |
      |                   void*
a.cc: In function 'void vlist_add(vlist*, vlist_element_type)':
a.cc:49:24: error: invalid conversion from 'void*' to 'vlist_element_type*' {aka 'long unsigned int*'} [-fpermissive]
   49 |         vl->a = realloc(vl->a, sizeof(vlist_element_type) * vl->asize);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                        |
      |                        void*
a.cc: In function 'vlist* prime_list(uint64_t)':
a.cc:63:22: error: invalid conversion from 'void*' to 'bool*' [-fpermissive]
   63 |     bool *nl = malloc(sizeof(int) * (x+1));
      |                ~~~~~~^~~~~~~~~~~~~~~~~~~~~
      |                      |
      |                      void*
a.cc: In function 'int main()':
a.cc:115:20: error: invalid conversion from 'void*' to 'int*' [-fpermissive]
  115 |     int *A = malloc(sizeof(int) * N);
      |              ~~~~~~^~~~~~~~~~~~~~~~~
      |                    |
      |                    void*