Arithmetic Progression Subsequences (2) X55634


Statement
 

pdf   zip

html

Write a program that reads an integer n>1 followed by a sequence of integers, and finds out whether the sequence contains a consecutive subsequence of length n that forms an arithmetic progression.

A consecutive subsequence of integers forms an arithmetic progression if the difference between two consecutive numbers equals a fixed integer value r. For instance, 4 5 6 7 is an arithmetic progression with r = 1, and 22 33 44 55 66 is an arithmetic progression with r = 11.

If the input sequence contains such a progression, the program must report the start number and the value r. Otherwise, the program must indicate "No arithmetic progression of length n found".

Input The input is an integer n>1, followed by a sequence of integers containing at least 2 elements.

Output If a progression subsequence of length n exists, the output is the first element of the subsequence and the value of r. Otherwise, the output is "No arithmetic progression of length n found".

Public test cases
  • Input

    4
    7 1 -2 4 5 6 7 12 15
    

    Output

    4 1
    
  • Input

    4
    7 1 -2 4 5 6 7 8 9 12 15
    
    

    Output

    4 1
    
  • Input

    5
    7
    1
    -2 10 21
    32
    43
    54 88 3 -5 -6
    
    

    Output

    10 11
    
  • Input

    5
    2 3 4 6 8 10 11 21
    

    Output

    No arithmetic progression of length 5 found
    
  • Information
    Author
    ProAl
    Language
    English
    Official solutions
    Python
    User solutions