Count Prime Numbers in a Range


Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 10M

Author:
Problem type

Description

請撰寫一個程式,輸入兩個整數 ab (1 ≤ a, b ≤ 10000),計算在區間 a ~ b (含邊界) 之間有多少個質數。

質數定義:大於 1,且只有 1 和自己可以整除的數。

Requirements

  1. 輸入

    • 兩個整數 a, b 且已知1 ≤ a, b ≤ 10000
  2. 規則

    • 區間為 min(a, b) 到 max(a, b)
    • 判斷區間內每個整數是否為質數
  3. 輸出

    • 輸出質數的數量

Input and Output

Sample 1 Sample 2 Sample 3
INPUT 1 10 20 10 30 20
OUTPUT 4 4 2

Explanation

以 Sample 3 為例,2030 這個區間有 23292 個質數。


Comments

There are no comments at the moment.