#P12226. Counting Happy Years

    ID: 14331 Type: Default 1000ms 256MiB

Counting Happy Years

Counting Happy Years

Given four integers a, b, c, and n, count the number of happy years from \(1\) to \(n\) (inclusive). A year \(y\) is considered a happy year if it satisfies one of the following conditions:

  • \(y\) is divisible by \(a\) and not divisible by \(b\), i.e. \(y \equiv 0 \pmod{a}\) and \(y \not\equiv 0 \pmod{b}\); or
  • \(y\) is divisible by \(c\), i.e. \(y \equiv 0 \pmod{c}\).

This definition is analogous to the leap year determination where the numbers \(4\), \(100\), and \(400\) are replaced by \(a\), \(b\), and \(c\), respectively.

inputFormat

The input consists of a single line containing four space-separated integers a, b, c, and n, where \(n\) represents the last year (starting from 1) to consider.

outputFormat

Output a single integer representing the number of happy years from 1 to \(n\) inclusive.

sample

4 100 400 50
12