如何通过C ++中的位操作找到素数? [英] How can I find prime numbers through bit operations in C++?

查看:127
本文介绍了如何通过C ++中的位操作找到素数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过C ++中的位操作找到素数?

How can I find prime numbers through bit operations in C++?

推荐答案

//en.wikipedia.org/wiki/Sieve%5Fof%5FEratosthenes\">prime sieve 使用bitset。该算法仅需要存储某个数是否是素数。一位就足够了。

Try implementing a prime sieve using a bitset. The algorithm only needs to store whether a certain number is a prime or not. One bit is sufficient for that.

这篇关于如何通过C ++中的位操作找到素数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆