AtCoder Beginner Contest 452
This is the weekly coding competition happens on every Saturday on the Atcoder platform
AtCoder Beginner Contest 452 Problem number E solution in python
MOD = 998244353
N, M = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))
N += 1
S = [t:=0] + [t:=t+a for a in A]
sa = sb = 0
for i in range(N):
sa = (sa + A[i]*i)%MOD
for j in range(1, M+1):
sb = (sb + B[j])%MOD
ans = sa*sb%MOD
for j in range(1, M+1):
for l in range(0, N, j):
r = min(N, l+j)
ans = (ans - (S[r]-S[l])*l*B[j])%MOD
print(ans)

