K-summary
Time limit0.5sMemory limit64 MB
Given segment lengths K_i, count how many array positions are pinned down by all the K_i-summaries.
- Level
Hard8 of 10
- Topics
- Math, Number theory, Prefix sum, Implementation
- Solved
- No attempts yet
Problem
An unknown array holds integers. The -summary of that array is what you get by cutting the array into segments of length from the front and adding up the elements of each segment. If is not divisible by , the last segment is shorter than .
In other words, the elements of the -summary are, in order, , , and so on, and only the last sum, the one that contains , can have fewer than terms. For example, the 5-summary of an array of 13 elements has three elements: the sum of elements 1 to 5, the sum of elements 6 to 10, and the sum of elements 11 to 13.
One -summary alone is not enough to recover the elements of the original array. If you know the summaries for several different values of , some elements are pinned down to a single value. You are given the length and the numbers . Write a program that computes how many elements of the original array are uniquely determined when all -summaries are known. That count does not depend on the values written in the summaries.
Input
The first line contains the array length and the number of summaries . (, )
The second line contains distinct integers . ()
Output
Print the number of elements that are uniquely determined.
Hint
In the first example, only can be determined.
In the second example, and can be determined.