Advertisement
Guest User

Untitled

a guest
Oct 26th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. public static int largestPrime(long n)
  2. {
  3. int limit=(int)Math.sqrt(n)+1;
  4. boolean [] numbers = new boolean[limit];
  5. Arrays.fill(numbers,true);
  6. int largestPrimeFactor=1;
  7. for(int count=2;count<limit;count++)
  8. {
  9. if(numbers[count]==true)
  10. {
  11. for(int i=2;i*count<limit;i++)
  12. numbers[count*i]=false;
  13. if(n%count==0)
  14. largestPrimeFactor=count;
  15. }
  16.  
  17. }
  18. return largestPrimeFactor;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement