unknown_0711

Untitled

Oct 20th, 2022
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. public class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. //your code here
  10. Scanner scanner = new Scanner(System.in);
  11. int n = scanner.nextInt();
  12. boolean[] arr = new boolean[n + 1];
  13. // initially all numbers are cube_free
  14. for(int i = 0; i<=n; i++)
  15. arr[i] = false;
  16.  
  17. for(int i = 2; i * i * i<=n; i++) {
  18. arr[i * i * i] = true;
  19. }
  20.  
  21. for(int i = 2; i<=n; i++) {
  22. if(arr[i]) {
  23. for(int j = 2; j * i <= n; j++) {
  24. arr[i * j] = true;
  25. }
  26. }
  27. }
  28.  
  29. if(arr[n]) {
  30. System.out.println(-1);
  31. return;
  32. }
  33. int cnt = 0;
  34. for(int i = 1; i<=n; i++) {
  35. if(!arr[i]) {
  36. cnt++;
  37. }
  38. }
  39. System.out.println(cnt);
  40. }
  41. }
Add Comment
Please, Sign In to add comment