素数筛法算法(C#)
2016-11-06 16:44
274 查看
using System; public class PrimeFilter { public static void Main(string[] args) { int N = 100; bool[] a = new bool[N + 1]; for (int i = 2; i <= N; i++) { a[i] = true; } for (int i = 2; i < N; i++) { if (a[i]) { for (int j = i * 2; j <= N; j += i) { a[j] = false; } } } for (int i = 2; i <= N; i++) { if (a[i]) { Console.Write(i + " "); } } Console.ReadKey(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PrimeFilter { class Program { static void Main(string[] args) { int N = 100; bool[] a = new bool[N + 1]; for (int i = 2; i <= N; i++) { a[i] = true; } for (int i = 2; i < N; i++) { if (a[i]) { for (int j = i * 2; j <= N; j += i) { a[j] = false; } } } for (int i = 2; i <= N; i++) { if (a[i]) { Console.Write(i + " "); } } Console.ReadKey(); } } }
相关文章推荐
- 已知圆心和两点画圆弧(算法)(计算机图形)(C#)
- 30种图像动画特效算法(C#多线程版)(中)
- 常用算法(C#): 计算 1+2(2次方)+3(3次方)+...+n(n次方)的值
- 控制随机抽中几率--C#算法
- C#泛型版的超级优化的快速排序算法和插入排序、二分查找算法
- 二元查找树转变成排序的双向链表之C#算法实现
- 数列:1,1,2,3,5,8,13,21,34,..... 求第50个数值? 并用c#写出算法?(不难,但要注意int 溢出问题)
- C#数据结构和算法学习系列五----基础查找算法
- C#下利用堆栈删除文件夹的算法
- 经典算法-C#四种排序算法
- c# MACD 算法实现
- 揽货最短路径解决方案算法 - C# 蚁群优化算法实现
- 算法 - 快速排序(C#)
- c# 加密解密算法 张宇轩
- C# 加密解密算法
- C#有意思的算法题
- 用C#截取指定长度的中英文混合字符串的最终算法
- 十大算法之一动态规划—解背包问题-C#代码
- C#实现的算24点游戏算法实例分析
- [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序