For N to be a stormer number, the highest prime factor of the expression N^2+1 must be greater than or equal to 2*N and it should be a positive integer.
For example, 4 is a stormer number. Since 4*4+1=17 has the greatest prime factor 17 itself which is greater than 8 i.e. 2*4.
但是3不是一个强力数字,因为3*3+1=10。10的最大质因数是5,小于6即2*3。
在这个问题中,我们给定一个正整数N,我们的目标是打印出前N个stormer。
输入: 4
OUTPUT: 1 2 4 5
这里是前4个斯托默数。3不是斯托默数,所以没有包括在内。
算法
找到数字(N^2+1)的最大质因数,并将其存储在任意变量中。
Check if the prime factor is larger than or equal to 2*N.
If it satisfies the condition hence it is a stormer number.
Print all the stormer numbers until i is less than or equal to N.
方法
To implement the above algorithm in our code, we need to make two functions. First, to find out the highest prime factor for each case and second to check if it is greater than or equal to 2*N and keep printing the number if it is a stormer number simultaneously.
For finding out the highest prime factor of expression (n^2+1) for every number n −
We will divide the number by 2 until it gives remainder 0 and store 2 in primemax.
现在,n在这一点上必须是奇数,所以我们将在一个for循环中迭代,只迭代从i=3到n的平方根的奇数。
Now store i in primemax and divide n by i while i divides n. When i fails to divide n then raise it by 2 and carry on.
如果n是一个大于2的质数,那么在前两个步骤中n不会变成1,因此我们将n存储在primemax中并返回primemax。
The next function will be to check if the number is a stormer number or not. If it is, we will print it.
我们将声明一个变量 temp 为 0,以计算前 N 个 stormer 数。
从i=1开始,在temp小于N之前进行for循环迭代。
检查 (i*i+1) 是否具有大于或等于 2*i 的最大质因数。如果上述条件为真,则打印 i 并将 temp 增加 1。
Example
的中文翻译为:示例
Below is the implementation of above approach in C++ −
#include <iostream> #include <bits/stdc++.h> using namespace std; int prime_factor(int n){ //for finding the maximum prime factor int primemax=0; while(n%2==0){ //if n is divided by 2 than we store 2 in primemax primemax=2; n=n/2; } for(int i=3;i<=sqrt(n);i+=2){ // this is only for odd number while(n%i==0){ primemax=i; n=n/i; } } if(n>2){ // when n is prime number and greater than 2 primemax=n; } return primemax; } void stormer_number(int n){ //function to print first n stormer numbers int temp=0; // for counting the stormer number for(int i=1;temp<n;i++){ // for iterating the all number int check=(i*i)+1; // for storing the (i*i)+1 value in check if(prime_factor(check)>=(2*i)){ //for checking the number if maximum prime is greater or equal to 2*i cout<<i<<" "; temp++; } } } int main(){ int n=9; stormer_number(n); return 0; }
Output
1 2 4 5 6 9 10 11 12
结论
在本文中,我们尝试解决打印前 N 个斯托默数的问题。
我们还学会了计算一个数的质因数。我希望这篇文章能帮助解决您对这个问题的所有疑惑。
以上是暴风雨数字的详细内容。更多信息请关注PHP中文网其他相关文章!

C#和C 在性能上的差异主要体现在执行速度和资源管理上:1)C 在数值计算和字符串操作上通常表现更好,因为它更接近硬件,没有垃圾回收等额外开销;2)C#在多线程编程上更为简洁,但性能略逊于C ;3)选择哪种语言应根据项目需求和团队技术栈决定。

1)c relevantduetoItsAverity and效率和效果临界。2)theLanguageIsconTinuellyUped,withc 20introducingFeaturesFeaturesLikeTuresLikeSlikeModeLeslikeMeSandIntIneStoImproutiMimproutimprouteverusabilityandperformance.3)

C 在现代世界中的应用广泛且重要。1)在游戏开发中,C 因其高性能和多态性被广泛使用,如UnrealEngine和Unity。2)在金融交易系统中,C 的低延迟和高吞吐量使其成为首选,适用于高频交易和实时数据分析。

C 中有四种常用的XML库:TinyXML-2、PugiXML、Xerces-C 和RapidXML。1.TinyXML-2适合资源有限的环境,轻量但功能有限。2.PugiXML快速且支持XPath查询,适用于复杂XML结构。3.Xerces-C 功能强大,支持DOM和SAX解析,适用于复杂处理。4.RapidXML专注于性能,解析速度极快,但不支持XPath查询。

C 通过第三方库(如TinyXML、Pugixml、Xerces-C )与XML交互。1)使用库解析XML文件,将其转换为C 可处理的数据结构。2)生成XML时,将C 数据结构转换为XML格式。3)在实际应用中,XML常用于配置文件和数据交换,提升开发效率。

C#和C 的主要区别在于语法、性能和应用场景。1)C#语法更简洁,支持垃圾回收,适用于.NET框架开发。2)C 性能更高,需手动管理内存,常用于系统编程和游戏开发。

C#和C 的历史与演变各有特色,未来前景也不同。1.C 由BjarneStroustrup在1983年发明,旨在将面向对象编程引入C语言,其演变历程包括多次标准化,如C 11引入auto关键字和lambda表达式,C 20引入概念和协程,未来将专注于性能和系统级编程。2.C#由微软在2000年发布,结合C 和Java的优点,其演变注重简洁性和生产力,如C#2.0引入泛型,C#5.0引入异步编程,未来将专注于开发者的生产力和云计算。

C#和C 的学习曲线和开发者体验有显着差异。 1)C#的学习曲线较平缓,适合快速开发和企业级应用。 2)C 的学习曲线较陡峭,适用于高性能和低级控制的场景。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3 Linux新版
SublimeText3 Linux最新版

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。