bhalash

Project Euler problem #3 solution.

May 30th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.44 KB | None | 0 0
  1. using System;
  2.  
  3. public class problem
  4. {
  5.     static void Main()
  6.     {
  7.         long    a = 600851475143;
  8.         int     b = Convert.ToInt32(Math.Sqrt(a));
  9.         int c = 0;
  10.  
  11.         for (int i = b; i >= 2; i--)
  12.         {
  13.             if (a % i == 0)
  14.                 c = ChkPrime(i);
  15.             if (c > 0)
  16.                 break;
  17.         }
  18.  
  19.         Console.WriteLine(c);
  20.     }
  21.  
  22.     static int ChkPrime(int c)
  23.     {
  24.         for (int i = 2; i < Math.Sqrt(c); i++)
  25.             if (c % i == 0)
  26.             {
  27.                 c = -1;
  28.                 break;
  29.             }
  30.  
  31.         return c;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment