Arithmetic Progression Subsequences (1)

Write a program that reads two integers n and r, both strictly greater
than 1, followed by a sequence of integers, and finds out whether the
sequence contains a consecutive subsequence of length at least n that
forms an arithmetic progression with step r.

A consecutive subsequence of integers forms an arithmetic progression
with step r if the difference between two consecutive numbers equals r.
For instance, 4567 is an arithmetic progression with r = 1, and
2233445566 is an arithmetic progression with r = 11.

If the input sequence contains such a progression, the program must
print a line with the first n elements in the progression. Otherwise,
the program must indicate "No arithmetic progression found with step r
and length at least n".

Input

The input consists of two integers n > 1 and r > 1, followed by a
sequence of integers containing at least 2 elements.

Output

If a progression subsequence with reason r and length at least n exists,
the output are the first n elements of the progression. Otherwise, the
output is "No arithmetic progression found with step r and length at
least n".

Problem information

Author: ProAl

Generation: 2026-01-25T17:02:55.462Z

© Jutge.org, 2006–2026.
https://jutge.org
