编程介的小学生 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),素数表可以先找到最大的值再构造。

    评论

报告相同问题?

悬赏问题

  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)