Multiple of Previous Two X23407


Statement
 

pdf   zip

html

Write a program that reads a sequence of positive integers and reports the first one that is a multiple of both two previous numbers in the sequence, together with the corresponding quotients.

Input

A sequence of positive integers i0, i1, i2, ... finished by the value -1 that marks the end and does not count as a member of the sequence. There is no constraint (neither upper nor lower) on the length of the sequence.

Output

The first value in in the sequence that is a multiple of both previous ones (that is, in is a multiple of in−1 and of in−2) together with the corresponding quotients (namely, in / in−1 and in / in−2). In case no element of the sequence fulfills this condition, the output should be 0 (the integer zero).

Observation

The usage of “break” is hereby explicitly forbidden.

Public test cases
  • Input

    29 27 4 5 40 41 39 42 38 -1

    Output

    40 8 10
    
  • Input

    666 -1

    Output

    0
    
  • Input

    2 3 12 48 -1

    Output

    12 4 6
    
  • Input

    15 8
    2 6
    6 7 42
    13
    -1

    Output

    6 1 3
    
  • Information
    Author
    José Luis Balcázar
    Language
    English
    Official solutions
    Python
    User solutions
    Python