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

推荐订阅源

人人都是产品经理
人人都是产品经理
Stack Overflow Blog
Stack Overflow Blog
S
SegmentFault 最新的问题
博客园 - 司徒正美
aimingoo的专栏
aimingoo的专栏
U
Unit 42
GbyAI
GbyAI
B
Blog RSS Feed
博客园 - Franky
L
LangChain Blog
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 三生石上(FineUI控件)
Microsoft Azure Blog
Microsoft Azure Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
G
Google Developers Blog
Last Week in AI
Last Week in AI
阮一峰的网络日志
阮一峰的网络日志
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research

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