需要一种方法来确定素数 [英] Need a way to determine Prime Numbers

查看:69
本文介绍了需要一种方法来确定素数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个程序的帮助,当你写一个数字时,它会确定它是否是素数。任何帮助都表示赞赏。

I am looking for some help on a program that when you write a number it will determine it if is prime or not. Any help is appreciated.

推荐答案


我正在寻找一些程序的帮助,当你写一个数字时将确定它是否是素数。任何帮助表示赞赏。
I am looking for some help on a program that when you write a number it will determine it if is prime or not. Any help is appreciated.



我建议你先在维基百科上查找素数。我没有检查过,但它可能会提供有关它们如何确定的信息。


另外,如果你想要一个简单的蛮力方法,数字 n 只测试从2到 n -1的每个数字,看它是否均匀分为 n 。如果是这样, n 不是素数。

I''d recommend you start by looking up primes on Wikipedia. I haven''t checked, but it will probably provide info on how they are determined.

Also, if you want a simple brute-force approach, for number n just test every number from 2 to n-1 to see whether it divides evenly into n. If so, n isn''t prime.



我建议你从查找开始维基百科上的素数。我没有检查过,但它可能会提供有关它们如何确定的信息。


另外,如果你想要一个简单的蛮力方法,数字 n 只测试从2到 n -1的每个数字,看它是否均匀分为 n 。如果是这样, n 并不是素数。
I''d recommend you start by looking up primes on Wikipedia. I haven''t checked, but it will probably provide info on how they are determined.

Also, if you want a simple brute-force approach, for number n just test every number from 2 to n-1 to see whether it divides evenly into n. If so, n isn''t prime.



蛮力在这里测试每个数字从2到n的平方根。

即便如此,这是蛮力。

brute-force works here testing every number from 2 to the square root of n.
even then, it''s brute force.



brute-force在这里测试从2到n的平方根的每个数字。

甚至那么,这是蛮力。
brute-force works here testing every number from 2 to the square root of n.
even then, it''s brute force.



每个人都可以使用一点蛮力;)

Everyone can use a little bit of brute force ;)


这篇关于需要一种方法来确定素数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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