Primal Partitions
Time limit2sMemory limit256 MB
Split the array into k consecutive segments to maximize the smallest segment score, where each segment scores its largest common prime factor or zero.
- Level
Hard8 of 10
- Topics
- Binary search, Dynamic programming, Number theory
- Solved
- No attempts yet
Problem
The math department challenged the computer science department to a puzzle in discrete mathematics.
You are given a sequence of positive integers. Split the sequence into consecutive regions. Every region holds at least one integer, and joining the regions in order gives back the original sequence.
A partition is scored like this. For each region, find the largest prime that divides every integer in that region. A prime is an integer greater than 1 whose only divisors are 1 and itself. If no prime divides every integer of the region, that region scores 0. The score of the partition is the smallest region score.
Find the largest score a partition into regions reaches.
Input
The first line contains the length of the sequence and the number of regions (, ).
The second line contains the integers of the sequence, in order ().
Output
Print one integer, the maximum score over all partitions of the sequence into regions.