Advertisement
Krefeld187

Untitled

Dec 30th, 2020
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. package Problem3;
  2.  
  3. public class LargestPrimeFaktor
  4. {
  5. static long s = 600851475143L ;
  6. static long primefa = 0;
  7.  
  8. public static void main(String[] args)
  9. {
  10. factor();
  11. System.out.print(primefa);
  12. }
  13.  
  14. public static void factor()
  15. {
  16. for(long i = (int)Math.sqrt(s); i >=1 ; --i)
  17. {
  18. if(s % i == 0 && isPrime(i) == true)
  19. {
  20. primefa = i;
  21. break;
  22. }
  23. }
  24. }
  25.  
  26. public static boolean isPrime(long n)
  27. {
  28. if (n <= 1)
  29. return false;
  30.  
  31. for (int i = 2; i < Math.sqrt(n); i++)
  32. {
  33. if (n % i == 0)
  34. return false;
  35. }
  36. return true;
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement