Given an integer N and an array of N integers, compute the sum of products of factorials for all pairs of indices. The product of factorials for each pair is calculated as F(Ai) * F(Aj) * (Ai + Aj) modulo 998244353.
Example 1:
Input:2
31435
[1, 2, 3]
Output:37
Example 2:
Input:5
115110010
[1, 2, 3, 4, 5]
Output:8358
Constraints:
1 <= N <= 10^5
1 <= Ai <= 10^5
The input array contains N integers
The output should be an integer modulo 998244353
solution.cpp
Loading...
Run code to see test results
00:00 / 69:42
Compute the Sum of Products of Factorials
MediumMed•392 views
Given an integer N and an array of N integers, compute the sum of products of factorials for all pairs of indices. The product of factorials for each pair is calculated as F(Ai) * F(Aj) * (Ai + Aj) modulo 998244353.