当前位置:网站首页>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
边栏推荐
- 杂七杂八的学习
- cmder中文乱码问题
- 第5 章 机器学习基础
- AVD Pixel_ 2_ API_ 24 is already running. If that is not the case, delete the files at C:\Users\admi
- 【2021年新书推荐】Red Hat RHCSA 8 Cert Guide: EX200
- 电脑关机程序
- 组件化学习(2)Arouter原理学习
- Fill the network gap
- torch. mm() torch. sparse. mm() torch. bmm() torch. Mul () torch The difference between matmul()
- [2021 book recommendation] practical node red programming
猜你喜欢
BottomSheetDialogFragment 与 ListView RecyclerView ScrollView 滑动冲突问题
ThreadLocal, just look at me!
Cause: dx. jar is missing
Viewpager2 realizes Gallery effect. After notifydatasetchanged, pagetransformer displays abnormal interface deformation
SSL/TLS应用示例
adb shell top 命令详解
What did you do during the internship
第8章 生成式深度学习
[2021 book recommendation] red hat rhcsa 8 cert Guide: ex200
Android清除应用缓存
随机推荐
GEE配置本地开发环境
adb shell常用模拟按键keycode
第3章 Pytorch神经网络工具箱
Personal blog website construction
电脑关机程序
torch_ Geometric learning 1, messagepassing
adb shell top 命令详解
HandlerThread原理和实际应用
Binder mechanism principle
【动态规划】最长递增子序列
Itop4412 cannot display boot animation (4.0.3_r1)
1.2 初试PyTorch神经网络
iTOP4412 SurfaceFlinger(4.0.3_r1)
1.1 PyTorch和神经网络
ProcessBuilder工具类
Bottom navigation bar based on bottomnavigationview
去掉状态栏
.net加载字体时遇到 Failed to decode downloaded font:
Cause: dx. jar is missing
杂七杂八的学习