Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
long num = 34568654219 ;
         long i ;
         int count = 0 ;



         for (long j = 3; j < num; j++)
         {

             for (i = 2; i < j; i++)
             {
                 if ((j % i) != 0)
                 {
                     count++;

                 }


                 if ((num % j) == 0)
                 {
                     count++;


                 }
             }

             if (count == 2)
             {
                 Console.WriteLine("the prime factors of 600851475143 are : " + j);


             }



             count = 0 ;

         }




         Console.ReadLine();
Posted

1 solution

Try this one. Hope it helps.

C#
int a, b;
Console.WriteLine("Please enter your integer: ");
a = int.Parse(Console.ReadLine());
for (b = 2; a > 1; b++)
    if (a % b == 0)
    {
        int x = 0;
        while (a % b == 0)
        {
            a /= b;
            x++;
        }
        Console.WriteLine("{0} is a prime factor {1} times!", b, x);
    }
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900