Programming contests

ECN selejtező programozó csapatverseny, 2015. április 19.

April 19, 2015, 10:10 AM – April 19, 2015, 3:10 PM

Magic Formula

You are given a quadratic function f(n) = ax2 + bx + c. You are also given a divisor d and a limit L. How many of the function values f(0), f(1), …, f(L) are divisible by d?

Input Specification

The input consists of a number of test cases. Each test case consists of a single line containing the numbers a, b, c, d, and L (–1000 ≤ a, b, c ≤ 1000, 1 < d < 1 000 000, 0 ≤ L < 1000).

The input is terminated by a line containing “0 0 0 0 0”, which should not be processed.

Output Specification

Print the answer for each test case (the number of function values f(0), f(1), …, f(L) divisible by d) in a separate line.

Sample Input

  1. 0 0 10 5 100
  2. 0 0 10 6 100
  3. 1 2 3 4 5
  4. 1 2 3 3 5
  5. 0 0 0 0 0
download as text file

Output for Sample Input

  1. 101
  2. 0
  3. 0
  4. 4
download as text file
University of Debrecen; Faculty of Informatics; v. 09/30/2024