#GL0000219. Phân rã bằng ước nguyên tố (Prime Destruction)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Phân rã bằng ước nguyên tố (Prime Destruction)
Phân rã bằng ước nguyên tố (Prime Destruction)
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a multiset of positive integers and an integer threshold , you may repeatedly choose any element and a prime divisor of , remove one occurrence of , and insert exactly copies of . Find the minimum number of operations until all multiset elements are at most . Newly inserted elements may also be transformed.
Input
The first line contains ; the second contains integers .
Output
Print the minimum number of operations.
Subtasks
-
Subtask 1 (20 points): ; .
-
Subtask 2 (30 points): ; .
-
Subtask 3 (50 points): ; .
Examples
Example 1
Input
6 2
6 6 4 3 2 1
Output
4
Explanation
Change each 6 into three 2s, change 4 into two 2s, and 3 into three 1s, using four operations.
Example 2
Input
1 1
1
Output
0
Explanation
Every element is at most k.
Example 3
Input
8 1
8 6 4 3 2 1 8 6
Output
25
Explanation
For k=1, use the minimum operation cost for each element and sum the independent costs.