#SP0000251. Lũ nguyên tố — Phiên bản khó (A Prime Flood — Hard Version)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 initial positive integer water levels . Independently consider every nonempty subsequence obtained by selecting indices while preserving order.
One operation selects a prime and simultaneously decreases by exactly every element of whose current value is divisible by . All other elements remain unchanged. Any number of operations is allowed, including zero. The objective is to make all elements equal.
Define as the largest integer to which all elements of can be made equal. Find the sum of over all nonempty subsequences, modulo .
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 .
The second line contains exactly integers in their original order.
Output
Print one integer in : the sum of over every nonempty subsequence, modulo .
Subtasks
- Subtask 1 (20 points): ; for every .
- Subtask 2 (30 points): ; for every .
- Subtask 3 (50 points): ; for every .
Examples
Input
4
2 4 4 4
Output
37
Explanation
There are three positions holding value . Choosing a nonempty subset of those positions gives subsequences, each contributing , so the subtotal is .
The singleton subsequence contributes .
The remaining subsequences each contain the value and at least one occurrence of . Every such subsequence has largest achievable common value , giving a subtotal of . Thus the output is .