编程介的小学生 2019-02-22 22:53 采纳率: 20.5%
浏览 855

一个素数的问题,但是求的是素数的个数,怎么利用C语言的办法解决的

Problem Description
Give you a lot of positive integers, just to find out how many prime numbers there are.

Input
There are a lot of cases. In each case, there is an integer N representing the number of integers to find. Each integer won’t exceed 32-bit signed integer, and each of them won’t be less than 2.

Output
For each case, print the number of prime numbers you have found out.

Sample Input
3
2 3 4

Sample Output
2

  • 写回答

2条回答

  • greatofdream 2019-02-22 23:57
    关注

    可以暴力解决,对于每一个数从2开始除道sqrt(N),检查是否为素数,复杂度O(n^1.5)

    要么维护一个素数表,可以每次查询,复杂度O(n),素数表可以先找到最大的值再构造。

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大