查找介于1和1000之间的Twin Primes [英] Find Twin Primes between 1 and 1000

查看:53
本文介绍了查找介于1和1000之间的Twin Primes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何计算所有孪生素数,然后加上有多少孪生素数?

a素数是任何数字,只能被1和它自己分割,而孪生素数是两个素数分开2(例如3和5)

这里是寻找素数的代码,如果它有帮助

how can i calculate all the twin primes, and then add up how many there are?
a prime is any number than can only be divised by 1 and itself, and a twin prime is two primes seperated by 2 ( for example 3 and 5)
here is code for finding a prime if it helps

展开 | 选择 | 换行 | 行号

推荐答案


如何计算所有的孪生素数,然后加起来有多少?

a prime是任何数字,只能用1和它来划分自我,孪生素数是由2分开的两个素数(例如3和5)

这里是寻找素数的代码,如果它有帮助
how can i calculate all the twin primes, and then add up how many there are?
a prime is any number than can only be divised by 1 and itself, and a twin prime is two primes seperated by 2 ( for example 3 and 5)
here is code for finding a prime if it helps
展开 | 选择 | Wrap | 行号


如何让它获取一个素数,然后查看列表中的下一个?
how can you get it to take one prime and then look at its next in the list?



你怎么能让它拿一个素数然后再看一下列表中的下一个?
how can you get it to take one prime and then look at its next in the list?



而不是cout''的数字,将它分配给一个数组(我建议阅读这个首先得到一个大概,然后这个更多关于如何处理记忆的信息 - 如果你感兴趣的话),然后创建两个tmp变量。


分配tmp变量(可能是:int tmp_var1,tmp_var2;)然后你可以使用一个循环来指向索引中的一对一位置,然后指向另一个位置。所以你有两个素数,你需要做的就是检查它们是否是孪生素数。


这是否有意义(即,你能构建一个算法(基本的步骤列表)那个)?

Instead of cout''ing the number, assign it to an array (I would recommend reading this first to get a general idea, and then this for a little more info into how memeory is handled - if you are interested), and then create two tmp variables.

Assign the tmp vars (possibly: int tmp_var1, tmp_var2;) then you can use a loop to go through and point one to one place in the index, and another to the place after. So you have two primes, and all you need to do is check if they are twin primes.

Does that make sense (ie, can you construct an algorithm (basic list of steps) from that)?


这篇关于查找介于1和1000之间的Twin Primes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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