为什么我们要检查质数的平方根以确定它是否为质数?

编程入门 行业动态 更新时间:2024-10-24 22:27:12
本文介绍了为什么我们要检查质数的平方根以确定它是否为质数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

要测试一个数字是否为质数,为什么我们必须测试该数字是否只能整除该数字的平方根?

To test whether a number is prime or not, why do we have to test whether it is divisible only up to the square root of that number?

推荐答案

如果数字 n 不是质数,则可以将其分为两个因素 a 和 b :

If a number n is not a prime, it can be factored into two factors a and b:

n = a * b

现在 a 和 b 不能都大于 n 的平方根,因为从那以后乘积 a * b 将大于 sqrt(n)* sqrt(n)= n 。因此,在 n 的任何因式分解中,至少一个因子必须小于 n 的平方根,并且如果找不到小于或等于平方根的因子,则 n 必须是质数。

Now a and b can't be both greater than the square root of n, since then the product a * b would be greater than sqrt(n) * sqrt(n) = n. So in any factorization of n, at least one of the factors must be smaller than the square root of n, and if we can't find any factors less than or equal to the square root, n must be a prime.

更多推荐

为什么我们要检查质数的平方根以确定它是否为质数?

本文发布于:2023-11-29 22:52:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647861.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:质数   平方根

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!