惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
C
CXSECURITY Database RSS Feed - CXSecurity.com
S
Schneier on Security
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
C
Cybersecurity and Infrastructure Security Agency CISA
Engineering at Meta
Engineering at Meta
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
T
Threat Research - Cisco Blogs
C
Cisco Blogs
Recent Announcements
Recent Announcements
S
Securelist
N
Netflix TechBlog - Medium
The Register - Security
The Register - Security
P
Privacy & Cybersecurity Law Blog
宝玉的分享
宝玉的分享
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
LINUX DO - 热门话题
T
Tor Project blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
月光博客
月光博客
AWS News Blog
AWS News Blog
P
Proofpoint News Feed
博客园 - 司徒正美
L
LINUX DO - 最新话题
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
H
Help Net Security
Spread Privacy
Spread Privacy
PCI Perspectives
PCI Perspectives
Project Zero
Project Zero
I
Intezer
T
The Blog of Author Tim Ferriss
有赞技术团队
有赞技术团队
The Last Watchdog
The Last Watchdog
C
Check Point Blog
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
MyScale Blog
MyScale Blog
V
Vulnerabilities – Threatpost
Recorded Future
Recorded Future
T
Tenable Blog
Jina AI
Jina AI
D
DataBreaches.Net
阮一峰的网络日志
阮一峰的网络日志

博客园 - kuning的程序博客

第一章 第二课 Using Resources 第一章 第一课 Using WPF Control Cmd,powershell 参考 百度WSUS 我也转关于软件测试的文章 了解WMI 英文面试题 据说是微软面试哦 算法 之 万年历 C# 理论学习 之 面向对象设计 C# 理论学习 之 类、组,名称空间 C# 深入学习 之 Winform记录日志 C#深入学习 之 委托和事件 C#数据结构-排序之快速排序法 .Net本地化资源 PHP之安装篇 Sql Server中的行列互换 再叙2005Web控件(一) - kuning的程序博客 - 博客园 Poket PC 与 sqlserver2000(以上) RDA 方案
算法 之 哥德巴赫猜想 - kuning的程序博客
kuning的程序博客 · 2010-03-29 · via 博客园 - kuning的程序博客
using System;

namespace Test
{
    class Program
    {

        /// <summary>
        /// 判断素数
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        static bool IsPrime(int n)
        {
            int j = (int)Math.Ceiling(Math.Sqrt(Convert.ToDouble(n)));
            bool intFlag = true;
            for (int i = 1; i <= j; i++)
            {
                if (n % i == 0 && (i != 1) && (i != n))
                {
                    intFlag = false;
                    break;
                }
            }
            return intFlag;

        }
        /// <summary>
        /// 输入一个数判断是否符合哥德巴赫猜想
        /// 大于6的偶数都可以表示成为两个素数之和
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        static bool IsGDBHArish(int n)
        {
            bool isG = false;
            if (n % 2 == 0 && n > 6)
            {
                for (int i = 1; i < n / 2; i++)
                {
                    bool b1 = IsPrime(i);
                    bool b2 = IsPrime(n - i);
                    if (b1 & b2)
                    {
                        Console.WriteLine("{0}={1}+{2}", n, i, n - i);
                        isG = true;
                    }

                }
            }
            return isG;
        }

       

        static void Main(string[] args)
        {
            //////素数
            int n = 1;

            while (n != -1)
            {
                Console.WriteLine("请输入一个数:");

                if (Int32.TryParse(Console.ReadLine(), out n))
                {
                    if (n == -1)
                        break;
                    //if (Program.IsPrime(n))
                    //{
                    //    Console.WriteLine("{0}是素数", n);
                    //}
                    //else
                    //{
                    //    Console.WriteLine("{0}不是素数", n);
                    //}

                    IsGDBHArish(n);
                }
                
            }


            Console.ReadLine();
        }
    }
}