暴风雨数字

小静小哥_3027

小静小哥_3027

2023-08-26

1470人浏览

转载

暴风雨数字

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 −

Powtoon
Powtoon

Powtoon是一款用于制作动画视频、演示文稿和品牌视觉内容的 AI 视频创作平台。

下载
  • 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>

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;i2){ // 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 for iterating the all number int check="(i*i)+1;" storing value in if>=(2*i)){ //for checking the number if maximum prime is greater or equal to 2*i
         cout<h3>Output</h3>
<pre class="brush:php;toolbar:false;">1 2 4 5 6 9 10 11 12

结论

在本文中,我们尝试解决打印前 N 个斯托默数的问题。

我们还学会了计算一个数的质因数。我希望这篇文章能帮助解决您对这个问题的所有疑惑。

相关文章

PHP速学视频免费教程(入门到精通)
PHP速学视频免费教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载

相关标签:

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
Sass和less的区别
Sass和less的区别

Sass和less的区别有语法差异、变量和混合器的定义方式、导入方式、运算符的支持、扩展性等。本专题为大家提供Sass和less相关的文章、下载、课程内容,供大家免费下载体验。

2023.10.12

3367

5

python中print函数的用法
python中print函数的用法

python中print函数的语法是“print(value1, value2, ..., sep=' ', end='\n', file=sys.stdout, flush=False)”。本专题为大家提供print相关的文章、下载、课程内容,供大家免费下载体验。

2023.09.27

3540

5

python print用法与作用
python print用法与作用

本专题整合了python print的用法、作用、函数功能相关内容,阅读专题下面的文章了解更多详细教程。

2026.02.03

269

24

while的用法
while的用法

while的用法是“while 条件: 代码块”,条件是一个表达式,当条件为真时,执行代码块,然后再次判断条件是否为真,如果为真则继续执行代码块,直到条件为假为止。本专题为大家提供while相关的文章、下载、课程内容,供大家免费下载体验。

2023.09.25

354

5

function是什么
function是什么

function是函数的意思,是一段具有特定功能的可重复使用的代码块,是程序的基本组成单元之一,可以接受输入参数,执行特定的操作,并返回结果。本专题为大家提供function是什么的相关的文章、下载、课程内容,供大家免费下载体验。

2023.08.04

3760

5

js函数function用法
js函数function用法

js函数function用法有:1、声明函数;2、调用函数;3、函数参数;4、函数返回值;5、匿名函数;6、函数作为参数;7、函数作用域;8、递归函数。本专题提供js函数function用法的相关文章内容,大家可以免费阅读。

2023.10.07

614

5

页面置换算法
页面置换算法

页面置换算法是操作系统中用来决定在内存中哪些页面应该被换出以便为新的页面提供空间的算法。本专题为大家提供页面置换算法的相关文章,大家可以免费体验。

2023.08.14

7216

4

Go-Zero API开发使用教程
Go-Zero API开发使用教程

本专题聚焦Go-Zero的API开发,拆解.api描述文件的语法结构、路由与分组定义、参数绑定与校验规则,说明统一响应体、JWT鉴权、跨域与接口文档生成的落地方式,并给出网关聚合与接口测试的实践建议。

2026.11.12

140

15

Go-Zero安装与goctl环境配置教程
Go-Zero安装与goctl环境配置教程

本专题围绕Go-Zero的安装与工具链配置展开,讲清Go版本要求、goctl安装方式、代理镜像、protoc依赖与环境变量设置,说明多版本共存、升级回退与CI流水线安装的做法,并整理安装阶段的常见报错与验证步骤。

2026.11.12

100

15

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
热门推荐
/
最新课程
phpStudy极速入门视频教程
phpStudy极速入门视频教程

共6课时 | 54.7万人学习

独孤九贱(4)_PHP视频教程
独孤九贱(4)_PHP视频教程

共89课时 | 134.3万人学习