Checksum
Time limit2sMemory limit1024 MB
Find the length N (at most 1000) and the digits K_i of a hidden periodic weight sequence, using checksum queries that contain no digit 0.
- Level
Medium5 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
A checksum detects errors that occur when data is transmitted or entered. Many algorithms have been invented for this purpose. This problem covers one of the simplest.
The checksum of a number sequence is
where are fixed constants. The sequence is treated as periodic. If is longer than , the elements of are used again from the beginning. If is shorter, some elements of are not used.
Juku found a system that uses this checksum. He does not know the length of the sequence or the values . He only knows that and . Juku can send queries to the system. Each query is a number sequence, and the system returns its checksum. The 0 key on Juku's keyboard is slightly broken, so 0 is hard to type. For this reason, he wants to avoid the digit 0 in his queries.
Write a program that finds the length of the sequence and the values of its elements. Since is periodic, there are infinitely many possible answers. Output the shortest one.