#C12792. Prime Number Finder
Prime Number Finder
Prime Number Finder
You are required to implement a program that finds all prime numbers in a given range. Specifically, your program will read two values start and end from standard input, and then print out all prime numbers in the interval \([start, end)\) (including start
if it is prime but excluding end
). If the input is invalid (i.e. the inputs are not integers), your program should output an error message. Additionally, if start \ge end
, your program should output nothing.
The prime checking should be optimized by testing divisibility only up to \(\sqrt{n}\). Please note that any negative number or a number less than 2 should not be considered as a prime. The error message to output in case of invalid input is:
[ \text{Invalid input: start and end must be integers.} ]
inputFormat
The input consists of two tokens separated by whitespace representing start
and end
. They are expected to be integers. For example:
10 20
outputFormat
If the input is valid and start < end
, output all prime numbers in the interval \([start,end)\) on a single line, separated by a space. If there are no prime numbers in the range, output an empty line. In case of invalid input, output the following error message:
Invalid input: start and end must be integers.## sample
10 20
11 13 17 19