Loading...
Loading...
Loading...
Print every prime number from a to b (both included) and how many there are. If there is no prime in the range, print No primes on the first line.
No primes. Line 2: Count: k.Example 1
Input
10 30
Output
11 13 17 19 23 29 Count: 6
11 13 17 19 23 29: six primes.
Example 2
Input
24 28
Output
No primes Count: 0
No primes between 24 and 28.
Try the problem first. Open one hint at a time.
Outer loop: every number from a to b. Inner loop: the √ prime test with break.
Keep a count of primes found. Use it to decide whether a space is needed before the next prime.
After the loop, if the count is 0, print No primes; otherwise end the line of primes.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor