Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.lang.*;
- import java.io.*;
- public class Main
- {
- public static void main (String[] args) throws java.lang.Exception
- {
- //your code here
- Scanner scanner = new Scanner(System.in);
- int n = scanner.nextInt();
- boolean[] arr = new boolean[n + 1];
- // initially all numbers are cube_free
- for(int i = 0; i<=n; i++)
- arr[i] = false;
- for(int i = 2; i * i * i<=n; i++) {
- arr[i * i * i] = true;
- }
- for(int i = 2; i<=n; i++) {
- if(arr[i]) {
- for(int j = 2; j * i <= n; j++) {
- arr[i * j] = true;
- }
- }
- }
- if(arr[n]) {
- System.out.println(-1);
- return;
- }
- int cnt = 0;
- for(int i = 1; i<=n; i++) {
- if(!arr[i]) {
- cnt++;
- }
- }
- System.out.println(cnt);
- }
- }
Add Comment
Please, Sign In to add comment