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

推荐订阅源

S
Secure Thoughts
P
Privacy International News Feed
T
Tenable Blog
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Threat Research - Cisco Blogs
S
Securelist
C
CXSECURITY Database RSS Feed - CXSecurity.com
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
P
Privacy & Cybersecurity Law Blog
Vercel News
Vercel News
Cyberwarzone
Cyberwarzone
月光博客
月光博客
T
The Blog of Author Tim Ferriss
Scott Helme
Scott Helme
爱范儿
爱范儿
Stack Overflow Blog
Stack Overflow Blog
C
Cisco Blogs
aimingoo的专栏
aimingoo的专栏
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
P
Proofpoint News Feed
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
L
LangChain Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
阮一峰的网络日志
阮一峰的网络日志
Simon Willison's Weblog
Simon Willison's Weblog
T
Tor Project blog
Security Latest
Security Latest
Blog — PlanetScale
Blog — PlanetScale
G
GRAHAM CLULEY
V
Vulnerabilities – Threatpost
博客园 - 三生石上(FineUI控件)
I
InfoQ
Spread Privacy
Spread Privacy
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
S
SegmentFault 最新的问题
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog
C
CERT Recently Published Vulnerability Notes
A
About on SuperTechFans
博客园_首页
Engineering at Meta
Engineering at Meta
Project Zero
Project Zero
Latest news
Latest news

博客园 - 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();
        }
    }
}