判断:

if 素数 then 1

if 不是素数 then 最小因子

        public static int isPrime(long n)
        {
            bool isFind = false;
            for (int i = 2; i <= n - 1; i++)
            {
                if (n % i == 0)
                {
                    //不是素数
                    isFind = true;
                    break;
                }
            }
            if (!isFind)
            {
                return 1;
            }
            else
            {
                return Result.SmallestDivisor(n);
            }

        }

        public static int SmallestDivisor(long n, int d = 2)
        {
            if (n % d == 0)
                return d;
            return SmallestDivisor(n, ++d);
        }

  

相关文章:

  • 2021-10-05
  • 2021-05-16
  • 2022-12-23
  • 2022-01-25
  • 2022-12-23
  • 2022-12-23
  • 2022-02-28
  • 2022-01-24
猜你喜欢
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2021-11-21
  • 2021-06-17
相关资源
相似解决方案