#C14711. Two Sum Pair Finder
Two Sum Pair Finder
Two Sum Pair Finder
You are given a list of integers and a target integer. Your task is to determine whether there exist two distinct numbers in the list that sum up to the target value.
The condition for a valid solution is that the list must consist entirely of integers. If any non-integer is present, the program should output an error message stating "All elements in the list must be integers."
Formally, given a list \(nums\) and an integer \(target\), you need to check if there exist indices \(i\) and \(j\) (\(i \neq j\)) such that:
\(nums[i] + nums[j] = target\)
Note: You must read the input from stdin
and write the result to stdout
. The output should be either True
or False
depending on whether such a pair exists.
inputFormat
The input consists of three lines:
- The first line contains a single integer \(n\) representing the number of elements in the list.
- The second line contains \(n\) space-separated integers.
- The third line contains a single integer representing the target value.
outputFormat
Output a single line to stdout
containing either True
if there exist two distinct numbers that sum up to the target, or False
otherwise.
5
1 2 3 4 5
9
True