Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

distinct prime factors count of a number

       public static int PrimeFactorsCount(int n)
        {
            if(n==1)
            {
                return 0;
            }
            var num = 0;
            if (n % 2 == 0)
            {
                num++;

                while (n % 2 == 0)
                {
                    n /= 2;
                }
            }

            for (int i = 3; i <= Math.Sqrt(n); i += 2)
            {
                if (n % i == 0)
                {
                    num++;

                    while (n % i == 0)
                    {
                        n /= i;
                    }
                }
            }

            if (n > 2)
                num++;
            return num;
       }
Comment

PREVIOUS NEXT
Code Example
Csharp :: add dependency injection .net core console app 
Csharp :: c# byte array to file 
Csharp :: how to close an application in c# 
Csharp :: getting the row of max value c# linq 
Csharp :: c# read file from directory 
Csharp :: linq from select 
Csharp :: yanderedev 
Csharp :: httpclient post c# example 
Csharp :: get diff btw datetimes two C# 
Csharp :: c# cast to int 
Csharp :: convert string to list int c# 
Csharp :: No Entity Framework provider found for the ADO.NET provider with invariant name 
Csharp :: list index out of range c# 
Csharp :: c# convert stream to memorystream 
Csharp :: change dot net core web api routing 
Csharp :: unity cast int to float 
Csharp :: c# Get all class by namespace 
Csharp :: c# get list of all class fields 
Csharp :: operator -- c# 
Csharp :: c# console clear 
Csharp :: difference between class and struct 
Csharp :: unity c# get direction of object 
Csharp :: windows form textbox password 
Csharp :: how to open onscreen keyboard c# 
Csharp :: c# remove rows from datatable 
Csharp :: unity no serializefield 
Csharp :: c# print decimal with zero at the end 
Csharp :: unity switch 
Csharp :: exceldatareader example c# 
Csharp :: c# round number up 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =