1、验证哥德马赫猜想(任何充分大的偶数都可由两个素数之和表示).将4—100中的所有偶数分别用两个素数之和表示.输出为4=2+2;6=3+3;8=3+5…100=3+97)
You're something,so please help me,and using C# to solve it,thank you

解决方案 »

  1.   

    先做一个list保存所有素数。
    然后对所有偶数循环-list里的素数,如果剩下的数在list里能找到,说明符合要求进行输出。
      

  2.   

        class Program
        {
            static void Main(string[] args)
            {
                for (int i = 4; i <= 100; i++)
                {
                    if (i%2==0)
                    {
                        for (int j = 2; j < i; j++)
                        {
                            if (IsSuShu(j) && IsSuShu(i-j))
                            {
                                Console.Write("{0}={1}+{2}; ",i,j,i-j);
                                break;
                            }
                        }
                    }
                }            Console.Read();
            }        private static bool IsSuShu(int iSuShu)
            {
                bool bIsSuShu = true;
                for (int i = 2; i < iSuShu; i++)
                {
                    if (iSuShu%i ==0)
                    {
                        return bIsSuShu = false;
                    }
                }
                return bIsSuShu;
            }
        }没有问题的话,请给分,哈哈
      

  3.   

    这个我是运行过的 绝对没有问题 输出的结果也是你想要的using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                //验证歌德马赫定律
                //输出为4=2+2;6=3+3;8=3+5…100=3+97)
                //首先判断有哪些质数
                int j = 4;
                string[] result = new string[25];
                result[0] = "2";
                result[1] = "3";
                result[2] = "5";
                result[3] = "7";
                for (int i = 2; i < 101; i++)
                {
                    if (i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0)
                    {
                        result[j] = i.ToString();
                        j++;
                    }            }
                int m = 0;
                //质数判断完成,开始做运算。
                for (int i = 4; i < 101; i++)
                {
                    for (int k = 0; k < result.Length - 1; k++)
                    {
                        for (m = k; m >= 0; m--)
                        {
                            if (Convert.ToInt32(result[k]) + Convert.ToInt32(result[m]) == i )
                            {
                                Console.Write(i + "=" + result[k] + "+" + result[m] + "\n");
                                k =+ result.Length;
                                break;
                            }
                        }
                    }
                    i++;
                }
                Console.Read();
            }
        }
    }
      

  4.   

    Thank you ,it's useful,Please look after me in future.folks