luogu#P4444. [COCI2017-2018#3] Sažetak

[COCI2017-2018#3] Sažetak

题目描述

An unknown array x consists of N integers. The K-summary of that array is obtained by dividing the array into segments of length K and summing up the elements in each segment. If N is not divisible by K, the last segment of the division will have less than K elements.

In other words, the K-summary is an array where the elements are, respectively: (x[1] + … + x[K]), (x[K+1] + … + x[2K]), and so on, where the last sum that contains x[N] can have less than K summands. For example, the 5-summary of an array of 13 elements has three elements (sum of elements 1.-5., sum of elements 6.-10., sum of elements 11.-13.).

It is clear that we cannot reconstruct the elements of the original array from the K-summary, but that might be possible if we knew several K-summaries for different Ks. Write a program that will, given length N and set K1K_1, K2K_2 , …, KMK_M , predict how many elements of the original array we would be able to uniquely determine if we knew all the KiK_i -summaries of the array. (It is not difficult to show that the number of reconstructed elements is independent of the content of the summaries.)

输入格式

The first line contains the integers N and M (3 <= N <= 10910^9 , 1 <= M <= 10), the array length and the number of K-summaries.

The second line contains distinct integersK1K_1, K2K_2 , …, KMK_M (2 <= KiK_i < N) from the task.

输出格式

You must output the required number of reconstructed elements

题目大意

题目描述

有一个长度为 NN 的未知数组 xx。这个数组的 KK-总和定义为将该数组分割为若干长度为 KK 的区间,并对每个区间中的元素分别求和的结果。如果 NN 不能被 KK 整除,则最后一个区间的元素数将少于 KK

换言之,KK-总和指的是一个数组,其中的元素分别为:(x1++xK)(x_1+\dots+x_K)(xK+1++x2K)(x_{K+1}+\dots+x_{2K}),以此类推;其中包含了 xNx_N 的元素,即最后一个元素,可以由少于 KK 个部分组成。例如,一个含有十三个元素的数组的 55-总和有三个元素(第一到第五项之和,第六到第十项之和,第十一到第十三项之和)

可以发现我们无法通过一个 KK-总和来重现原数组,但当我们知道几个 KK 值不同的 KK-总和时就有可能做到这一点。给定 NNK1,K2,,KMK_1,K_2,\dots,K_M,请您编写一条程序,计算在已知一个长为 NN 的数组的 KiK_i-总和的前提下,有多少原数组的元素可以被唯一确定(不难发现唯一确定的元素数与 KiK_i-总和的内容无关)。

输入格式

第一行包含两个整数 NNMMNN 为原数组大小,MM 为已知 KK-总和的数量。

第二行包含 MM 个整数,分别为 K1,K2,,KMK_1,K_2,\dots,K_M,如题所述。

输出格式

您需要输出唯一确定的元素数。

数据范围

对于 40%40\% 的数据,N5×106N\le5\times10^6

对于 100%100\% 的数据,3N1093\le N\le10^91M101\le M\le102Ki<N2\le K_i<N

样例解释

对于第一个样例:我们可以确定 x3x_3

对于第二个样例:我们可以确定 x3x_3x4x_4

翻译来自于 @阿丑

3 1
2

1
6 2
2 3

2
123456789 3
5 6 9

10973937

提示

In test cases worth 40% of total points, it will hold N <= 5 000 000.

Clarification​ ​of​ ​the​ ​first​ ​example:​ ​We can determine one element: x[3].

Clarification​ ​of​ ​the​ ​second​ ​example:​ ​We can determine x[3] and x[4].