PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000251. Lũ nguyên tố — Phiên bản khó (A Prime Flood — Hard Version)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Lũ nguyên tố — Phiên bản khó (A Prime Flood — Hard Version)

A Prime Flood (Hard Version)

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn initial positive integer water levels a1,a2,…,ana_1,a_2,\ldots,a_n. Independently consider every nonempty subsequence bb obtained by selecting indices while preserving order.

One operation selects a prime pp and simultaneously decreases by exactly 11 every element of bb whose current value is divisible by pp. All other elements remain unchanged. Any number of operations is allowed, including zero. The objective is to make all elements equal.

Define f(b)f(b) as the largest integer to which all elements of bb can be made equal. Find the sum of f(b)f(b) over all nonempty subsequences, modulo 998244353998244353.

Subsequences selected using different sets of indices are counted separately, even if their values coincide. Every subsequence is processed independently from its original values.

Input

The first line contains the length nn.

The second line contains exactly nn integers a1,a2,…,ana_1,a_2,\ldots,a_n in their original order.

Output

Print one integer in [0,998244352][0,998244352]: the sum of f(b)f(b) over every nonempty subsequence, modulo 998244353998244353.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤ai≤n1\le a_i\le n for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤30001\le n\le 3000; 1≤ai≤n1\le a_i\le n for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤3000001\le n\le 300000; 1≤ai≤n1\le a_i\le n for every 1≤i≤n1\le i\le n.

Examples

Input

4
2 4 4 4

Output

37

Explanation

There are three positions holding value 44. Choosing a nonempty subset of those positions gives 23−1=72^3-1=7 subsequences, each contributing 44, so the subtotal is 7⋅4=287\cdot4=28.

The singleton subsequence [2][2] contributes 22.

The remaining 77 subsequences each contain the value 22 and at least one occurrence of 44. Every such subsequence has largest achievable common value 11, giving a subtotal of 77. Thus the output is 28+2+7=3728+2+7=37.