#QHD0000074. Chọn tập có nhiều chữ số 0 cuối (Round Subset)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Chọn tập có nhiều chữ số 0 cuối (Round Subset)
Round Subset
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integers , choose exactly distinct indices and multiply the numbers at those indices. The roundness of a positive integer is the number of trailing zero digits in its decimal representation: has roundness , has roundness , and has roundness .
Find the maximum attainable roundness over all choices of exactly indices. Equal values at different indices may both be selected, but no index may be used twice.
Each input number can reach , so the chosen product may not fit in a 64-bit integer. You should reason about the counts of prime factors and rather than multiply the selected numbers.
Input
The first line contains . The second line contains positive integers .
Output
Print one integer: the maximum number of trailing zeroes in the product of exactly selected elements.
Subtasks
-
Subtask 1 (20 points): ; ; choose exactly indices.
-
Subtask 2 (30 points): ; ; choose exactly indices.
-
Subtask 3 (50 points): ; ; choose exactly indices.
Examples
Example 1
Input
3 2
50 4 20
Output
3
Explanation
The pairs yield (two zeros), (one zero), and (three zeros), respectively; therefore the maximum is .
Example 2
Input
5 3
15 16 3 25 9
Output
3
Explanation
Selecting gives the product , ending with three zeros; no selection does better.
Example 3
Input
3 3
9 77 13
Output
0
Explanation
None of the numbers contributes a factor or , so the product has no trailing zeroes.