C#分解质因数

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace app
{
    class Program
    {
        static void Main(string[] args)
        {

            int n = int.Parse(Console.ReadLine());
            
            string n1 = Convert.ToString(n);
            int i=2;
            string str = "";
            if (n < 2)
            {
                Console.Write(n);
            }
            while (i <= n)
            {
                while (n % i == 0)
                {
                    n = n / i;

                    str += i;
                    if (i<=n)
                    {
                        str += "x";
                    }
                }
                i++;        

            }
                Console.WriteLine(n1+ "=" + str);
                Console.ReadKey();
            }
        
        }
    
}

猜你喜欢

转载自www.cnblogs.com/tianranhui/p/10127465.html
今日推荐