Problem:


Score : 700 points

Problem Statement

We have an integer sequence of length N: A_0,A_1,\cdots,A_{N-1}.

Find the following sum (\mathrm{lcm}(a, b) denotes the least common multiple of a and b):

\sum_{i=0}^{N-2} \sum_{j=i+1}^{N-1} \mathrm{lcm}(A_i,A_j)

Since the answer may be enormous, compute it modulo 998244353.

Constraints

1 \leq N \leq 200000

1 \leq A_i \leq 1000000

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_0\ A_1\ \cdots\ A_{N-1}

Output

Print the sum modulo 998244353.

Sample Input 1

3
2 4 6

Sample Output 1

22

\mathrm{lcm}(2,4)+\mathrm{lcm}(2,6)+\mathrm{lcm}(4,6)=4+6+12=22.

Sample Input 2

8
1 2 3 4 6 8 12 12

Sample Output 2

313

Sample Input 3

10
356822 296174 484500 710640 518322 888250 259161 609120 592348 713644

Sample Output 3

353891724



Sample input:
3
2 4 6


Sample output:
22

Submission status: Runtime Error

Solution code:
#C
#モジュール
import math
#入力
N=int(input())
A=list(map(int, input().split()))
x=0
#処理
for i in range(N-1):
    
    
    for j in range(i+1,N):
        
        x+=A[i]*A[j]//math.gcd(A[i],A[j])
print(x%998244353)

Submission status: Runtime Error

Solution code:

def gcd(a,b): 
    if a == 0: 
        return b 
    return gcd(b % a, a) 
  
# Function to return LCM of two numbers 
def lcm(a,b): 
    return (a*b) / gcd(a,b) 
n = input()
numList = list(map(int, input().split()))
out = 0
for num in numList:
    for o_num in otherNum(num):
         out += lcm(num, o_num)
print(out)

Submission status: Runtime Error

Solution code:

/// @file lcm.cc
/// @brief lcm の実装ファイル
/// @author Yusuke Matsunaga (松永 裕介)
///
/// Copyright (C) 2019 Yusuke Matsunaga
/// All rights reserved.


#include <iostream>
#include <vector>
#include <unordered_map>


using namespace std;

bool debug = false;

class ModInt
{
public:

  ModInt(long val = 0);

  ~ModInt() = default;

  operator long() const;

  static
  const long mMagicNumber = 998244353;


private:

  long mVal;

};

ModInt
operator+(const ModInt& left,
	  const ModInt& right);

ModInt
operator-(const ModInt& left,
	  const ModInt& right);

ModInt
operator*(const ModInt& left,
	  const ModInt& right);

ostream&
operator<<(ostream& s,
	   const ModInt& val)
{
  s << static_cast<long>(val);
  return s;
}

inline
ModInt::ModInt(long val) :
  mVal(val)
{
}

inline
ModInt::operator long() const
{
  return mVal;
}

inline
ModInt
operator+(const ModInt& left,
	  const ModInt& right)
{
  auto a = static_cast<long>(left);
  auto b = static_cast<long>(right);
  auto c = a + b;
  if ( c > ModInt::mMagicNumber ) {
    c %= ModInt::mMagicNumber;
  }
  else if ( c < 0 ) {
    while ( c < 0 ) {
      c += ModInt::mMagicNumber;
    }
  }
  return ModInt{c};
}

inline
ModInt
operator-(const ModInt& left,
	  const ModInt& right)
{
  auto a = static_cast<long>(left);
  auto b = static_cast<long>(right);
  auto c = a - b;
  if ( c > ModInt::mMagicNumber ) {
    c %= ModInt::mMagicNumber;
  }
  else if ( c < 0 ) {
    while ( c < 0 ) {
      c += ModInt::mMagicNumber;
    }
  }
  return ModInt{c};
}

inline
ModInt
operator*(const ModInt& left,
	  const ModInt& right)
{
  auto a = static_cast<long>(left);
  auto b = static_cast<long>(right);
  auto c = a * b;
  if ( c > ModInt::mMagicNumber ) {
    c %= ModInt::mMagicNumber;
  }
  else if ( c < 0 ) {
    while ( c < 0 ) {
      c += ModInt::mMagicNumber;
    }
  }
  return ModInt{c};
}

int
main(int argc,
     char** argv)
{
  bool debug = false;

  int n;
  cin >> n;

  long max_val = 0;

  // 各要素の配列
  vector<long> A(n);

  // 各値の出現回数
  vector<int> h(1000000, 0);
  for ( int i = 0; i < n; ++ i ) {
    int val;
    cin >> val;
    A[i] = val;
    ++ h[val];
    if ( max_val < val ) {
      max_val = val;
    }
  }

  // 出現回数に値自身を掛けたもの
  vector<long> v(max_val + 1);
  for ( int i = 1; i <= max_val; ++ i ) {
    v[i] = h[i] * i;
  }

  //Factoring factoring(max_val);

  // Wd を計算する．
  vector<long> W(max_val + 1);
  W[0] = 0; // 例外：どうせ使わないけど．
  for ( int i = 1; i <= max_val; ++ i ) {
    W[i] = 1;
  }
  for ( int i = 1; i <= max_val; ++ i ) {
    //cout << "W[" << i << "] = " << W[i] << endl;
    // i の倍数の係数を調整する．
    for ( int j = i * 2; j <= max_val; j += i ) {
      W[j] -= W[i] * (j / i);
    }
  }

  ModInt ans = 0;
  for ( int x = 1; x <= max_val; ++ x ) {
    // x の倍数の対の値の総和を求める．
    long sum = 0;
    long diff = 0;
    for ( int val1 = x; val1 <= max_val; val1 += x ) {
      sum += v[val1];
      diff += v[val1] * val1;
    }
    long val = (sum * sum - diff) / 2;
    if ( val == 0 ) {
      // この x は使われない．
      continue;
    }
    auto tmp = ModInt{W[x]} * ModInt{val / x};
    //cout << "w * val = " << tmp << endl;
    ans = ans + tmp;
    //cout << "ans = " << ans << endl;
  }

  cout << ans << endl;

  return 0;
}

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    V=100
    W=[1 for i in range(V+1)]
    # Eratosthenes sieve (O(VloglogV))
    S=[1]*(V+1)
    S[0]=0; S[1]=0
    for p in range(2,V):
        if S[p]==0: continue
        W[p]*=1-p
        for k in range(2*p,V+1,p):
            W[k]*=1-p
            S[k]=0
    W=[W[i]/i if i else 0 for i in range(V+1)]
    n,k=map(int,input().split())
    ans=0
    for d in range(1,k+1):
        if k%d==0:
            ans+=d*W[d]*(n//d)*(n//d+1)//2%MOD
    print(round(ans)*k%MOD)
resolve()

Submission status: Runtime Error

Solution code:
import scipy

DIV = 998244353

N = int(input())
A = list(map(int, input().split()))

ret = 0
for i in range(N-2+1):
    for j in range(i + 1, N-1+1):
        ret += scipy.lcm(A[i], A[j])


print(ret % DIV)

Submission status: Runtime Error

Solution code:
import scipy

DIV = 998244353

N = int(input())
A = list(map(int, input().split()))

ret = 0
for i in range(N-2+1):
    for j in range(i + 1, N-1+1):
        ret = ret + scipy.lcm(A[i], A[j])


print(ret % DIV)

Submission status: Runtime Error

Solution code:
import scipy

DIV = 998244353

N = int(input())
A = list(map(int, input().split()))

ret = 0
for i in range(N-2+1):
    for j in range(i + 1, N-1+1):
        # print(f"{A[i]} {A[j]} {lcm(A[i], A[j])}")
        ret = ret + scipy.lcm(A[i], A[j])


print(ret % DIV)

Submission status: Runtime Error

Solution code:
import scipy

DIV = 998244353

N = int(input())
A = list(map(int, input().split()))

ret = 0
for i in range(N-2+1):
    for j in range(i + 1, N-1+1):
        # print(f"{A[i]} {A[j]} {lcm(A[i], A[j])}")
        ret += scipy.lcm(A[i], A[j])


print(ret % DIV)

Submission status: Runtime Error

Solution code:
from scipy import lcm

DIV = 998244353

N = int(input())
A = list(map(int, input().split()))

ret = 0
for i in range(N-2+1):
    for j in range(i + 1, N-1+1):
        # print(f"{A[i]} {A[j]} {lcm(A[i], A[j])}")
        ret += lcm(A[i], A[j])


print(ret % DIV)

Submission status: Runtime Error

Solution code:
from collections import deque

N, K = map(int, input().split())
P = list(map(int, input().split()))

maxQ = deque([])
minQ = deque([])

for i in range(K):
    while maxQ:
        if P[maxQ[-1]] <= P[i]:
            maxQ.pop()
        else:
            break
    maxQ.append(i)
    if maxQ[0] == i - K:
        maxQ.popleft()
    while minQ:
        if P[minQ[-1]] >= P[i]:
            minQ.pop()
        else:
            break
    minQ.append(i)
    if minQ[0] == i - K:
        minQ.popleft()

ans = 1
for left in range(N - K):
    right = left + K
    if P[left] <= P[minQ[0]] and P[right] >= P[maxQ[-1]]:
        pass
    else:
        ans += 1

    while maxQ:
        if P[maxQ[-1]] <= P[right]:
            maxQ.pop()
        else:
            break
    maxQ.append(right)
    if maxQ[0] == right - K:
        maxQ.popleft()
    while minQ:
        if P[minQ[-1]] >= P[right]:
            minQ.pop()
        else:
            break
    minQ.append(right)
    if minQ[0] == right - K:
        minQ.popleft()

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd


def p_c():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0

    for i in range(N):
        for j in range(i + 1, N):
            g = gcd(A[i], A[j])
            l = A[i] * A[j] // g
            # print("GCD: {}".format(g))
            # print("LCM: {}".format(l))
            ans += l
            ans %= 998244353

    print(ans)


if __name__ == '__main__':
    p_c()

Submission status: Runtime Error

Solution code:
#AGC C
import math
n=int(input())
a=list(map(int,input().split()))
s=0
for i in range(n-1):
    for j in range(i+1,n):
        s=(s+(a[i]*a[j])//(math.gcd(a[i],a[j])))%998244353
print(s)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

#aを破壊的にgcd-zetaする
def zeta_gcd(a):
    n = len(a)-1
    seive = [True]*(n+1)
    for p in range(2,n):
        if seive[p]:
            for i in range(n//p,0,-1):
                seive[p*i] = False
                a[i] += a[p*i]
                a[i] %= MOD
#    return a

#aを破壊的にgcd-mobiusする
def mobius_gcd(a):
    n = len(a)
    seive = [True]*(n+1)
    for p in range(2,n):
        if seive[p]:
            for i in range(1,n):
                if i*p >= n: break
                seive[p*i] = False
                a[i] -= a[p*i] 
                a[i] %= MOD
#    return a

################################################

#################################################

SIZE=1000001; MOD=998244353 #ここを変更する

SIZE += 1
inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
inv[1] = 1
for i in range(2,SIZE):
    inv[i] = MOD - (MOD//i)*inv[MOD%i]%MOD

################################################
#################################################
import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]

num = [0]*SIZE
for i in a: num[i] += i

assert n != 3

zeta_gcd(num)
ans = [i*i for i in num]
mobius_gcd(ans)

res = 0
for i,c in enumerate(ans):
    res = (res + c*inv[i])%MOD
for i in a:
    res = (res-i)%MOD
        
print(res*inv[2]%MOD)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

#aを破壊的にgcd-zetaする
def zeta_gcd(a):
    n = len(a)-1
    seive = [True]*(n+1)
    for p in range(1,n):
        if seive[p]:
            for i in range(n//p,0,-1):
                a[i] += a[p*i]
                a[i] %= MOD
#    return a

#aを破壊的にgcd-mobiusする
def mobius_gcd(a):
    n = len(a)
    seive = [True]*(n+1)
    for p in range(1,n):
        if seive[p]:
            for i in range(1,n):
                if i*p >= n: break
                a[i] -= a[p*i] 
                a[i] %= MOD
#    return a

################################################

#################################################

SIZE=1000001; MOD=998244353 #ここを変更する

SIZE += 1
inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
inv[1] = 1
for i in range(2,SIZE):
    inv[i] = MOD - (MOD//i)*inv[MOD%i]%MOD

################################################
#################################################
import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]

num = [0]*SIZE
for i in a: num[i] += i

assert n != 3

zeta_gcd(num)
ans = [i*i for i in num]
mobius_gcd(ans)

res = 0
for i,c in enumerate(ans):
    res = (res + c*inv[i])%MOD
for i in a:
    res = (res-i)%MOD
        
print(res*inv[2]%MOD)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
def Eratosthenes(N): #N以下の素数のリストを返す
    #iが素数のときis_prime_list[i]=1，それ以外は0
    N+=1
    is_prime_list = [True]*N
    m = int(N**0.5)+1
    for i in range(3,m,2):
        if is_prime_list[i]:
            is_prime_list[i*i::2*i]=[False]*((N-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,N,2) if is_prime_list[i]]

#aを破壊的にgcd-zetaする
def zeta_gcd(a):
    n = len(a)-1
    seive = [True]*(n+1)
    for p in range(1,n):
        if seive[p]:
            for i in range(n//p,0,-1):
                a[i] += a[p*i]
                a[i] %= MOD
#    return a

#aを破壊的にgcd-mobiusする
def mobius_gcd(a,primes):
    n = len(a)
    seive = [True]*(n+1)
    for p in range(1,n):
        if seive[p]:
            for i in range(1,n):
                if i*p >= n: break
                a[i] -= a[p*i] 
                a[i] %= MOD
#    return a

################################################

#################################################

SIZE=1000001; MOD=998244353 #ここを変更する

SIZE += 1
inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
inv[1] = 1
for i in range(2,SIZE):
    inv[i] = MOD - (MOD//i)*inv[MOD%i]%MOD

################################################
#################################################
import sys
#sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 

n = int(input())
a = [int(i) for i in readline().split()]

num = [0]*SIZE
for i in a: num[i] += i

assert n != 3

zeta_gcd(num)
ans = [i*i for i in num]
mobius_gcd(ans)

res = 0
for i,c in enumerate(ans):
    res = (res + c*inv[i])%MOD
for i in a:
    res = (res-i)%MOD
        
print(res*inv[2]%MOD)

Submission status: Runtime Error

Solution code:
import math
def lcm(x,y):
  return (x*y)//math.gcd(x,y)
n = int(input())
l=list(map(int,input().split()))
se = set()
s=0
se.add(l[0])
for i in range(1,n):
  for j in se:
    s+=lcm(l[i],j)%(998244353);
  se.add(l[i])
print(s%(998244353))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
N=int(input())
A=np.array(list(map(int, input().split())))
Sum=0
def Tem(a,b):
    return b/math.gcd(a,b)

for i in range(N-1):
    for j in range(i+1,N):
        Sum+=A[i]*Tem(A[i],A[j])%998244353

print(int(Sum%998244353))
def Tem(a,b):
    return b/math.gcd(a,b)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
N=int(input())
A=np.array(list(map(int, input().split())))
Sum=0
for i in range(N-1):
    for j in range(i+1,N):
        Tem=A[j]/math.gcd(A[i],A[j])
        Sum+=A[i]*Tem%998244353
print(int(Sum%998244353))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
N=int(input())
A=np.array(list(map(int, input().split())))
Sum=0
for i in range(N-1):
    for j in range(i+1,N):
        Sum+=A[i]*A[j]%998244353/math.gcd(A[i],A[j])
print(int(Sum%998244353))

Submission status: Runtime Error

Solution code:

from sys import stdin
import math

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0

def lcm(a, b):
    y = a * b / math.gcd(a, b)
    return int(y)

for i in range(0, N-1):
    for j in range(i+1,N):
        a = lcm(A[i],A[j])
        ans += a

a = ans%998244353
print(a)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
  while b:
	  a, b = b, a % b
  return a

def lcm(a, b):
	return a * b // gcd (a, b)

vlcm = np.vectorize(lcm)

A = np.array(a, dtype='uint32')
A_m = vlcm(np.tile(A,(n,1)), np.tile(A,(n,1)).T)
print(np.sum(np.triu(A_m, k=1)) % 998244353)

Submission status: Runtime Error

Solution code:
def gcd(a ,b):
    while b:
        a, b = b, a%b
    return a

def lcm(a, b):
    return a * b// gcd(a,b)

N = int(input())
A = list(map(int,input().split()))
A.sort()

c = 0

old_i = A[0]
old_j = A[1]
old_t = lcm(A[0],A[1])
for i in range(N-1):
    for j in range(i+1,N):
        if old_i == A[i] and old_j == A[j]:
            c += old_t
        else:
            t = lcm(A[i],A[j])
            c += t
            old_i = A[i]
            old_j = A[j]
            old_t = t

print(c%998244353)

Submission status: Runtime Error

Solution code:
import numpy as np
import math
N=int(input())
A=np.array(list(map(int, input().split())))
Sum=0
for i in range(N-1):
    for j in range(i+1,N):
        Sum+=A[i]*A[j]/math.gcd(A[i],A[j])%998244353
print(int(Sum%998244353))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
N=int(input())
A=np.array(list(map(int, input().split())))
Sum=0
for i in range(N-1):
    for j in range(i+1,N):
        Sum+=A[i]*A[j]/math.gcd(A[i],A[j])
print(int(Sum%998244353))

Submission status: Runtime Error

Solution code:

from sys import stdin
import math

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

ans = 0

def lcm(a, b):
    y = a*b / math.gcd(a, b)
    return int(y)

for i in range(0, N-1):
    for j in range(i+1,N):
        a = lcm(A[i],A[j])
        ans += a
print(ans%998244353)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
  while b:
	  a, b = b, a % b
  return a

def lcm(a, b):
	return a * b // gcd (a, b)

vlcm = np.vectorize(lcm)

A = np.array(a)
A_m = vlcm(np.tile(A,(n,1)), np.tile(A,(n,1)).T)
print(np.sum(np.triu(A_m, k=1)) % 998244353)

Submission status: Runtime Error

Solution code:
n=int(input())
A=[int(x) for x in input().split()]
import itertools
#import fractions
from functools import lru_cache
#com = list(itertools.combinations(A, 2))
res = 0
waru=998244353

@lru_cache(maxsize=None)
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a % b)

@lru_cache(maxsize=None)
def lcm(x,y):
    r = (x * y) // gcd(x, y) % waru
    return r

@lru_cache(maxsize=None)
def goukei(i,j):
    if j < n-1:
        return lcm(A[i],A[j]) + goukei(i,j+1)
    else:
        return lcm(A[i],A[j])

for i in range(n-1):
    res += goukei(i,i+1)
#for a, b in com:
    #res += lcm(a,b)

print(res % waru)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
A = []
A = input().split()
A = [int(n) for n in A]

print('N', N)
print('A', A)

tot = 0

for i in range(N-1) :
  for j in range(N-(i+1)) :
    print(A[i], A[i+j+1])
    tot = tot + gcd(A[i], A[i+j+1])

print(tot % 998244353)

Submission status: Runtime Error

Solution code:
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a
    

def lcm(x, y):
    ans = int((x * y) / gcd(x, y))
    return ans


N = int(input())
A = input().split()
S = 0
for i in range(N):
    A[i] = int(A[i])

for i in range(N-1):
    for j in range(i+1,N):
        
        S += lcm(A[i],A[j])
        
        

print(S = S % 998244353)

Submission status: Runtime Error

Solution code:
import sys
import math

pos=input()

N=int(pos)
print(N)
A=input()
A=A.split()
sum=0
A=[int(item) for item in A]
for i in range(0,N-1):
    for j in range(i+1,N):
        sum=sum+int(A[i]*A[j]/math.gcd(A[i],A[j]))
print(int(sum%998244353))

Submission status: Runtime Error

Solution code:
import math 

def least(x, y):
    ans = int((x * y) / math.gcd(x, y))
    return ans


N = int(input())
A = input().split()
S = 0
for i in range(N):
    A[i] = int(A[i])

for i in range(N-1):
    for j in range(i+1,N):
        
        S += least(A[i],A[j])
        S = S % 998244353
        

print(S)

Submission status: Runtime Error

Solution code:
import math 

def least(x, y):
    ans = int((x * y) / math.gcd(x, y))
    return ans

A = input().split()
N = int(input())

S = 0
for i in range(len(A)):
    A[i] = int(A[i])

for i in range(N-1):
    for j in range(i+1,N):
        
        S += least(A[i],A[j])
        S = S % 998244353
        

print(S)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(len(a)-1):
    for j in range(i+1, len(a)):
        lcm = a[i] // math.gcd(a[i], a[j]) * a[j]
        ans += lcm

print(ans % 998244353)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(len(a)-1):
    for j in range(i+1, len(a)):
        lcm = a[i] * a[j] // math.gcd(a[i], a[j])
        ans += lcm

print(ans % 998244353)

Submission status: Runtime Error

Solution code:
import math 

def least(x, y):
    ans = int((x * y) / math.gcd(x, y))
    return ans


N = int(input())
A = input().split()
S = 0
for i in range(len(A)):
    A[i] = int(A[i])

for i in range(N-1):
    for j in range(i+1,N):
        
        S += least(A[i],A[j])
        S = S % 998244353
        

print(S)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
n = [int(i) for i in input().split()]

lcm = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        a = n[i]
        b = n[j]
       
        lcm += (a * b) // math.gcd(a, b)

print(lcm % 998244353)

Submission status: Runtime Error

Solution code:
import math 
import sys
sys.setrecursionlimit(41000000000)
def lcm(x, y):
    ans = int((x * y) / math.gcd(x, y))
    return ans


N = int(input())
A = input().split()
S = 0
for i in range(len(A)):
    A[i] = int(A[i])

for i in range(N-1):
    for j in range(i+1,N):
        
        S += lcm(A[i],A[j])
        S = S % 998244353
        

print(S)

Submission status: Runtime Error

Solution code:
import math 
import sys
sys.setrecursionlimit(2000000000000000000000000000000000000000000)
def lcm(x, y):
    ans = int((x * y) / math.gcd(x, y))
    return ans


N = int(input())
A = input().split()
S = 0
for i in range(len(A)):
    A[i] = int(A[i])

for i in range(N-1):
    for j in range(i+1,N):
        
        S += lcm(A[i],A[j])
        S = S % 998244353
        

print(S)

Submission status: Runtime Error

Solution code:
import math

MOD = 998244353

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

N = int(input())
A = [int(x) for x in input().split()]

amari = 0

for i in range(N):
    for j in range(i+1,N):
        amari = (amari + lcm(A[i],A[j])) % MOD

print(amari)

Submission status: Runtime Error

Solution code:
import math 
import sys
sys.setrecursionlimit(200000)
def lcm(x, y):
    ans = int((x * y) / math.gcd(x, y))
    return ans


N = int(input())
A = input().split()
S = 0
for i in range(len(A)):
    A[i] = int(A[i])

for i in range(N-1):
    for j in range(i+1,N):
        
        S += lcm(A[i],A[j])
        S = S % 998244353
        

print(S)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
a = list(map(int, input().split()))

ans = 0
for i in range(len(a)):
    for j in range(i+1, len(a)):
        lcm = a[i] * a[j] // math.gcd(a[i], a[j])
        ans += lcm

print(ans % 998244353)

Submission status: Runtime Error

Solution code:
import math

MOD = 998244353

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

N = int(input())
A = [int(x) for x in input().split()]

sum = 0

for i in range(N):
    for j in range(i+1,N):
        sum = (sum + lcm(A[i],A[j])) % MOD

print(sum)

Submission status: Runtime Error

Solution code:
import numpy 

def lcm(x, y):
    ans = int((x * y) / numpy.gcd(x, y))
    return ans


N = int(input())
A = input().split()
S = 0
for i in range(len(A)):
    A[i] = int(A[i])

for i in range(N-1):
    for j in range(i+1,N):
        
        S += lcm(A[i],A[j])
        S = S % 998244353
        

print(S)

Submission status: Runtime Error

Solution code:
import sys
import math

pos=input()

N=int(pos[0])
A=input()
A=A.split()
sum=0
A=[int(item) for item in A]
for i in range(0,N-1):
    for j in range(i+1,N):
        sum=sum+int(A[i]*A[j]/math.gcd(A[i],A[j]))

print(sum%998244353)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
A = list(map(int, input().split()))
sum = 0


def lcm(a, b):
    return a*b//math.gcd(a, b)


for i in range(n-1):
    for j in range(1, n):
        if i >= j:
            continue
        sum += lcm(A[i], A[j])

sum = sum%998244353
print(sum)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

answer = 0
for i in range(N-1):
    for j in range(i+1, N):
        answer += lcm(A[i], A[j])
    answer %= 998244353

print(answer)N = int(input())
A = list(map(int, input().split()))

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(x, y):
    return (x * y) // gcd(x, y)

answer = 0
for i in range(N-1):
    for j in range(i+1, N):
        answer += lcm(A[i], A[j])
    answer %= 998244353

print(answer)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
A = list(map(int, input().split()))
sum = 0


def lcm(a, b):
    return a*b//math.gcd(a, b)


for i in range(n-1):
    for j in range(1, n):
        if i >= j:
            continue
        sum += lcm(A[i], A[j])

print(sum%998244353)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys
import numpy as np

inFile = ''
#inFile = 'test3.txt'
if inFile != '':
    f = open(inFile, 'r')
    sys.stdin = f
input = sys.stdin.readline

def lineInput(tList):#ex. tList = 'sdf'
    buf = list(input().strip().split())
    ret = []
    for i in range(len(tList)):
        if tList[i]=='d':
            ret.append(int(buf[i]))
        elif tList[i]=='f':
            ret.append(float(buf[i]))
        else:
            ret.append(buf[i])
    return ret

def gridInput(N):
    grid = []
    t = 'd'*N
    for i in range(N):
        array  = lineInput(t)
        grid.append(array)
    return grid

def outputList(l):
    for i,d in enumerate(l):
        if i < len(l)-1:
            print(d, end=" ")
        else:
            print(d)    

def outputGrid(grid):
    for x in grid:
        outputList(x)
            
#[n] = lineInput("d")
#g = gridInput(n)
#outputGrid(g)

def modlog(x, y):
    r = x % y
    return r

def gcd(x, y):
    r = modlog(x, y)
    while r != 0:
        x = y
        y = r
        r = modlog(x, y)
    return y

def kobai(x,y):
    z = int(np.gcd(int(x),int(y)))
    return int(x)*int(y)/z

def mondai(N, List):
    ret=0
    for i in range(0,N-1):
        for j in range(i+1,N):
            x = kobai(List[i],List[j])
            ret += x
            ret %= 998244353
    return int(ret)

[N] = lineInput("d")
s = "d"*N
List = lineInput(s)

ans = mondai(N, List)

print(ans)

Submission status: Runtime Error

Solution code:
import math

def lcm(x, y):
    ans = int((x * y) / math.gcd(x, y))
    return ans


N = int(input())
A = input().split()
S = 0
for i in range(len(A)):
    A[i] = int(A[i])

for i in range(N-1):
    for j in range(i+1,N):
        
        S += lcm(A[i],A[j])
        S = S % 998244353
        

print(S)

Submission status: Runtime Error

Solution code:
import math

mod = 998244353

n = int(input())
a = list(map(int, input().split()))


def lcm(x, y):
    return (x * y) // math.gcd(x, y) % mod


ans = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        ans += lcm(a[i], a[j])
print(ans % mod)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import sys
import numpy as np

inFile = ''
#inFile = 'test3.txt'
if inFile != '':
    f = open(inFile, 'r')
    sys.stdin = f
input = sys.stdin.readline

def lineInput(tList):#ex. tList = 'sdf'
    buf = list(input().strip().split())
    ret = []
    for i in range(len(tList)):
        if tList[i]=='d':
            ret.append(int(buf[i]))
        elif tList[i]=='f':
            ret.append(float(buf[i]))
        else:
            ret.append(buf[i])
    return ret

def gridInput(N):
    grid = []
    t = 'd'*N
    for i in range(N):
        array  = lineInput(t)
        grid.append(array)
    return grid

def outputList(l):
    for i,d in enumerate(l):
        if i < len(l)-1:
            print(d, end=" ")
        else:
            print(d)    

def outputGrid(grid):
    for x in grid:
        outputList(x)
            
#[n] = lineInput("d")
#g = gridInput(n)
#outputGrid(g)

def modlog(x, y):
    r = x % y
    return r

def gcd(x, y):
    r = modlog(x, y)
    while r != 0:
        x = y
        y = r
        r = modlog(x, y)
    return y

def kobai(x,y):
    z = np.gcd(x,y)
    return x*y/z

def mondai(N, List):
    ret=0
    for i in range(0,N-1):
        for j in range(i+1,N):
            x = kobai(List[i],List[j])
            ret += x
            ret %= 998244353
    return int(ret)

[N] = lineInput("d")
s = "d"*N
List = lineInput(s)

ans = mondai(N, List)

print(ans)

Submission status: Runtime Error

Solution code:
import math

def lcm(a, b):
  return a * b // math.gcd(a, b)

N = int(input())
A = list(map(int, input().split()))

ret = 0
for i in range(N-1):
  for j in range(i+1, N):
    ret += lcm(A[i], A[j])
    if ret > 998244353:
      ret %= 998244353

print(ret)

Submission status: Runtime Error

Solution code:
import math
import sys
sys.setrecursionlimit(10**6)
N = int(input())
A = list(map(int , input().split()))
#result = 0;
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

def sigma2(func, frm, to):
    result1 = 0; #答えの受け皿
    for i in range(frm, to+1):
        result1 += func(A[frm - 1],A[i])
        #ここで関数を呼び出す。ちなみにここではi = x
    return result1
def sigma(sigma2, frm, to):
    result = 0; #答えの受け皿
    for i in range(frm, to+1):
        result += sigma2(lcm,i + 1,N - 1)
        result %= 998244353
        #ここで関数を呼び出す。ちなみにここではi = x
    return result

if __name__ == "__main__":
    print(sigma(sigma2,0,N - 2) )

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = 0

import math

for i in range(n):
    for j in range(n):
        s += a[i] * a[j] // math.gcd(a[i], a[j])

s -= sum(a)
ans = s // 2

print(ans % 998244353)

Submission status: Runtime Error

Solution code:
import math

mod = 998244353

n = int(input())
a = list(map(int, input().split()))


def lcm(x, y):
    return (x * y) // math.gcd(x, y) % mod


ans = 0
for i in range(n - 1):
    for j in range(i+1,n):
        ans += lcm(a[i], a[j])
print(ans%mod)

Submission status: Runtime Error

Solution code:
import math

def lcm(x, y):
    ans = int((x * y) / math.gcd(x, y))
    return ans


N = int(input())
A = input().split()
S = 0
for i in range(len(A)):
    A[i] = int(A[i])

for i in range(N-1):
    for j in range(i+1,N):
        S += lcm(A[i],A[j])
        S = S % 998244353

print(S)

Submission status: Runtime Error

Solution code:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 998244353

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

n = INT()
a = MAP()
ans=0

for i in range(n-1):
    for j in range(i+1,n):
        ans+=lcm(a[i],a[j])
    ans%=MOD

print(ans)

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = list(map(int , input().split()))
#result = 0;
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

def sigma2(func, frm, to):
    result1 = 0; #答えの受け皿
    for i in range(frm, to+1):
        result1 += func(A[frm - 1],A[i])
        #ここで関数を呼び出す。ちなみにここではi = x
    return result1
def sigma(sigma2, frm, to):
    result = 0; #答えの受け皿
    for i in range(frm, to+1):
        result += sigma2(lcm,i + 1,N - 1)
        result %= 998244353
        #ここで関数を呼び出す。ちなみにここではi = x
    return result

if __name__ == "__main__":
    print(sigma(sigma2,0,N - 2) )

Submission status: Runtime Error

Solution code:
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 998244353

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

n = INT()
a = MAP()
ans=0

for i in range(n-1):
    for j in range(i+1,n):
        ans+=lcm(a[i],a[j])
    ans%=MOD

print(ans)