Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static int largestPrime(long n)
- {
- int limit=(int)Math.sqrt(n)+1;
- boolean [] numbers = new boolean[limit];
- Arrays.fill(numbers,true);
- int largestPrimeFactor=1;
- for(int count=2;count<limit;count++)
- {
- if(numbers[count]==true)
- {
- for(int i=2;i*count<limit;i++)
- numbers[count*i]=false;
- if(n%count==0)
- largestPrimeFactor=count;
- }
- }
- return largestPrimeFactor;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement