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

推荐订阅源

aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
M
MIT News - Artificial intelligence
Microsoft Azure Blog
Microsoft Azure Blog
月光博客
月光博客
Engineering at Meta
Engineering at Meta
I
InfoQ
T
Tailwind CSS Blog
N
Netflix TechBlog - Medium
S
SegmentFault 最新的问题
H
Help Net Security
博客园 - 【当耐特】
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
博客园 - 叶小钗
T
The Blog of Author Tim Ferriss
腾讯CDC
雷峰网
雷峰网
Martin Fowler
Martin Fowler
The GitHub Blog
The GitHub Blog
D
Docker

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