Distinct Numbers
InterviewTime limit2sMemory limit512 MB
Given integers a and b, count how many distinct values appear among the ten expressions a+b, a-b, a*b, a/b, a^b and their swapped forms, skipping invalid ones.
- Level
Medium4 of 10
- Topics
- Implementation, Math, Hash map, Brute force
- Solved
- No attempts yet
Problem
The other day Alice was cleaning her room and found a diary she kept in elementary school. In it she was surprised to find an entry about how amazed she was that . Unbelievable, multiplication and addition give the same result!
That entry led Alice to the following problem. Given integers and , how many distinct values are there in the set of numbers
, , , , ,
, , , , .
Division is performed without rounding, and the result of a division need not be an integer. If any expression in this set is invalid, Alice does not consider it. Division by zero and raising zero to a non-positive power count as invalid.
Input
The first line of the input file contains integers and separated by a space ().
Output
Print the number of distinct numbers in the given set.