0% found this document useful (0 votes)
5 views1 page

Find N-th Number Divisible by Two

The document outlines a problem where one must find the n-th natural number that is divisible by exactly two out of three given integers a, b, and c. It specifies input and output requirements, including constraints on the values of a, b, c, and n. If the n-th number does not exist or exceeds 10^18, the output should be -1.

Uploaded by

devvratmishra20
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Find N-th Number Divisible by Two

The document outlines a problem where one must find the n-th natural number that is divisible by exactly two out of three given integers a, b, and c. It specifies input and output requirements, including constraints on the values of a, b, c, and n. If the n-th number does not exist or exceeds 10^18, the output should be -1.

Uploaded by

devvratmishra20
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Two out of Three

Input file: standard input


Output file: standard output
Time limit: 1 second
Memory limit: 256 megabytes

The ancient Greek philosopher Pythagoras placed great importance on numbers, considering them the
foundation of the world. Numbers that possessed certain mathematical properties were attributed mystical
meanings. For example, odd numbers in Pythagoreanism were considered masculine, while even numbers
were considered feminine. The divisibility of a number by others was a significant distinguishing feature
for Pythagoras. Now he is interested in numbers that are sufficiently divisible but not entirely perfect in
this regard. To this end, he has written down an increasing sequence of natural numbers that are divisible
by exactly two out of three predetermined numbers a, b, and c. Help Pythagoras find the n-th number in
this sequence.

Input
The first line contains the integers a, b, c (1 ≤ a, b, c ≤ 106 ), which Pythagoras checks for divisibility.
The second line contains an integer n (1 ≤ n ≤ 1018 ) — the index of the element in the sequence that
Pythagoras wants to find. The elements are numbered starting from one.

Output
Output the n-th natural number that is divisible by exactly two of the three numbers a, b, c.
If such a number does not exist or exceeds 1018 , output −1.

Examples
standard input standard output
2 3 5 42
10
5 6 7 13999986
1000000

Note
The sequence of natural numbers that are divisible by exactly two of the three numbers 2, 3, and 5 looks
like this: 6, 10, 12, 15, 18, 20, 24, 36, 40, 42, 45, 48, 50, . . . . The tenth term of this sequence is 42.

Page 1 of 1

You might also like