Advertisement
Guest User

Untitled

a guest
Nov 9th, 2022
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class BiggestPrimeSecond {
  5. public static void main(String[] args) {
  6. Scanner scanner = new Scanner(System.in);
  7.  
  8. int n = Integer.parseInt(scanner.nextLine());
  9.  
  10. Boolean[] isPrime = new Boolean[n + 1];
  11. Arrays.fill(isPrime, true);
  12.  
  13.  
  14. for (int i = 2; i < Math.sqrt(n); i++) {
  15. if (isPrime[i]) {
  16. for (int j = i * i; j <= n; j+= i) {
  17. isPrime[j] = false;
  18. }
  19. }
  20.  
  21. }
  22.  
  23. for (int i = isPrime.length - 1; i > 0 ; i--) {
  24. if (!isPrime[i]) {
  25. continue;
  26. }
  27. System.out.println(i);
  28. return;
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement