#P103. Prime number

Prime number

題目描述

Given a integer 'num' you need to check whether it is a prime number or not.

for each test case there's only one query, so you do not need to build a prime table to optimized your solution just solve it in plain way.

 

In math, prime numbers are whole numbers greater than 1, that have only two factors – 1 and the number itself.

Prime numbers are divisible only by the number 1 or itself.

輸入格式

an Integer num

2<=num<=99999

輸出格式

if num is prime number then print '%d is a prime number' %num

else print '%d is not a prime number' %num

Samples

["2","3","8"]
["2 is a prime number","3 is a prime number","8 is not a prime number"]

提示

when there's exist a factor 'f' then num/'f' is also it's factor, so you only need to check the factors until int(sqrt(num))

原始資料

  • Zero1 題號:a103
  • Hydro 題號:Z0103
  • Locale:zh_TW
  • Display:open