为什么我们检查高达质数的平方根,以确定它是否是黄金?

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

要测试一个数是否是素数还是不为什么我们还要测试它是否是唯一的整除高达这个数字的平方根?

To test whether a number is prime or not why do we have to test whether it is divisible only upto 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 将大于 N 。因此,这些因素至少有一个必须小于或等于平方根 N ,并检查 N 是素数,我们只需要测试因子小于或等于平方根

If both a and b were greater than the square root of n, a*b would be greater than n. So at least one of those factors must be less or equal to the square root of n, and to check if n is prime, we only need to test for factors less than or equal to the square root.

更多推荐

为什么我们检查高达质数的平方根,以确定它是否是黄金?

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

发布评论

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

>www.elefans.com

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