YTU OJ 1606: 对称三位数素数

YTU OJ 1606: 对称三位数素数

在这里插入图片描述

using System;
class Program
{
    
    
    static void Main(String[] agrs)
    {
    
    
        string num;
        method method = new method();
        while (String.IsNullOrEmpty(num = Console.ReadLine()) == false)
        {
    
    
            method.shuru(num);
        }
    }
}

class method
{
    
    
    string[] str;

    int num1;
    public string shuru(string num)
    {
    
    
        str = num.Split(' ');
        for (var i = 0; i < str.Length; i++)
        {
    
    
            bool x = int.TryParse(str[i], out num1);
            cal();
        }
        return num;
    }
    public void cal()
    {
    
    
        var sum = 0;
        if (num1 >99)
        {
    
    
            var a = Convert.ToInt32( Math.Sqrt(num1));
            for (var i = 2; i <a; i++)
            {
    
    
                if (num1 % i != 0)
                {
    
    
                    sum += 1;
                }
            }
            if (sum == a - 2)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
        else
        {
    
    
            Console.WriteLine("No");
        }
    }
}

猜你喜欢

转载自blog.csdn.net/henishu/article/details/115113058
今日推荐