当前位置:网站首页>N states of prime number solution
N states of prime number solution
2022-04-23 07:19:00 【Amyniez】
The first one is : The basic method
//4. Judge i Prime or not , Primes are numbers that can only be 1 And the number divisible by itself
// lookup 1-100 The prime between
#include <math.h>
#include <stdio.h>
int main()
{
int i = 0;
int count = 0;
for (i = 1; i <= 100; i++)
{
// Trial division
int j = 0;
for (j = 2; j <= i; j++)
{
if (i%j == 0)
{
break;
}
}
if (j == i)
{
count++;
printf("%d ", i);
}
}
printf("\ncount = %d\n", count);
return 0;
}
The second kind : Modify the search method , Use the square method to reduce the number of searches
int main()
{
int i = 0;
int count = 0;
for (i = 1; i <= 100; i++)
{
// Trial division
int j = 0;
for (j = 2; j <= sqrt(i); j++)// Square root
{
if (i%j == 0)
{
break;
}
}
if (j >sqrt (i))
{
count++;
printf("%d ", i);
}
}
printf("\ncount = %d\n", count);
return 0;
}
The third realm : Look for prime numbers in odd numbers
int main()
{
int i = 0;
int count = 0;
for (i = 1; i <= 100; i+=2)// Look for prime numbers in odd numbers
{
// Trial division
int j = 0;
for (j = 2; j <= i; j++)
{
if (i%j == 0)
{
break;
}
}
if (j == i)
{
count++;
printf("%d ", i);
}
}
printf("\ncount = %d\n", count);
return 0;
}
版权声明
本文为[Amyniez]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230610096579.html
边栏推荐
- Migrating your native/mobile application to Unified Plan/WebRTC 1.0 API
- Itop4412 surfaceflinger (4.4.4_r1)
- 第1章 NumPy基础
- WebView displays a blank due to a certificate problem
- Itop4412 cannot display boot animation (4.0.3_r1)
- torch. mm() torch. sparse. mm() torch. bmm() torch. Mul () torch The difference between matmul()
- C#新大陆物联网云平台的连接(简易理解版)
- 素数求解的n种境界
- Using queue to realize stack
- Markdown basic grammar notes
猜你喜欢

红外传感器控制开关

常用UI控件简写名

【2021年新书推荐】Effortless App Development with Oracle Visual Builder

Cause: dx. jar is missing

组件化学习(1)思想及实现方式

Easyui combobox 判断输入项是否存在于下拉列表中
![Android interview Online Economic encyclopedia [constantly updating...]](/img/48/dd1abec83ec0db7d68812f5fa9dcfc.png)
Android interview Online Economic encyclopedia [constantly updating...]

1.2 初试PyTorch神经网络
![[2021 book recommendation] learn winui 3.0](/img/1c/ca7e05946613e9eb2b8c24d121c2e1.png)
[2021 book recommendation] learn winui 3.0

基于BottomNavigationView实现底部导航栏
随机推荐
How to standardize multidimensional matrix (based on numpy)
1.1 PyTorch和神经网络
ffmpeg常用命令
第1章 NumPy基础
Component based learning (1) idea and Implementation
Recyclerview batch update view: notifyitemrangeinserted, notifyitemrangeremoved, notifyitemrangechanged
[dynamic programming] longest increasing subsequence
[recommendation for new books in 2021] professional azure SQL managed database administration
this. getOptions is not a function
红外传感器控制开关
取消远程依赖,用本地依赖
C# EF mysql更新datetime字段报错Modifying a column with the ‘Identity‘ pattern is not supported
What did you do during the internship
Markdown basic grammar notes
电脑关机程序
[2021 book recommendation] red hat rhcsa 8 cert Guide: ex200
xcode 编译速度慢的解决办法
第3章 Pytorch神经网络工具箱
MySQL笔记4_主键自增长(auto_increment)
Reading notes - activity