该程序的任何不同的简单逻辑C ++最后的素数之前 [英] Any Different Simple Logic Of That Program C++ last prime number Before

查看:103
本文介绍了该程序的任何不同的简单逻辑C ++最后的素数之前的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个棘手的程序,可以很好的考试

但是有没有更简单的编码逻辑,我在这里找到了一个逻辑,但似乎很难



http:// fahad-cprogramming。 blogspot.com/2013/02/find-last-prime-number-occur-before.html [ ^ ]





请分享如果有人..



感谢您的时间..

Here is a tricky program which can be good for exam
But is there any more simple logic to code that i found a logic here but seems difficult

http://fahad-cprogramming.blogspot.com/2013/02/find-last-prime-number-occur-before.html[^]


Please Share If Anyone Got..

Thanks For Your Time..

推荐答案

我们不要做你的功课:这是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。



如果你发现它有困难的逻辑 然后我怀疑你将要完全被淹没,也许应该考虑一个不同的职业......因为这是一种蛮力,没有精巧的简单方法:你不能变得更简单,尽管你可以变得更优雅。
We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

And if you find that to have "difficult logic" then I suspect you are about to be completely overwhelmed, and should perhaps consider a different career...because that is a brute force, no finesse simple method: you can't get much simpler, though you can get a lot more elegant.


Man,该算法非常简单:对于给定的输入 n ,它从开始搜索( n-1)向下寻找素数(这是外环)。

对于每个素数候选者,它使用素数定义来测试素数:重复尝试找到一个精确的除数(这意味着你知道,'不是素数'。这是由内循环执行的。

有更高效的算法,但这可能是最简单的算法。
Man, that algorithm is really simple: for the given input n it searches, starting from (n-1) downwards for a prime number (this is the outer loop).
For every prime-number-candidate it uses the prime number definition for testing primality: repeadly attempts to find an exact divisor (that would mean 'not a prime number', you know). That's performed by the inner loop.
There are more efficient algorithms but that is possibly the simplest one.


这篇关于该程序的任何不同的简单逻辑C ++最后的素数之前的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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