1134 -- 区间质数统计

来源:互联网 发布:sql查询去除重复项 编辑:程序博客网 时间:2024/05/17 03:37

区间质数统计

Time Limit:1000MS  Memory Limit:65536K
Total Submit:293 Accepted:200

Description

你的任务是找出[a,b]区间的所有质数个数

Input

两个整数 a b

Output

区间[a,b]的所有质数个数

Sample Input

1 10

Sample Output

4

Hint

4

Source

    using System;    using System.Collections.Generic;    using System.Linq;    using System.Text;    namespace AK1134 {        class Program {            static bool prime(int n) {                if (n == 1) return false;                if (n == 2) return true;                for (int i = 2; i * i <= n; i++)                    if (n % i == 0)                        return false;                return true;            }            static void Main(string[] args) {                string[] s = Console.ReadLine().Split();                int[] a = new int[2];                int n = int.Parse(s[0]), m = int.Parse(s[1]);                int count = 0;                for (int i = n; i <= m; i++)                    if (prime(i))                        count++;                Console.WriteLine(count);            }        }    }


0 0