We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
My code which is passing few test cases, gives wrong answer in few test cases and times out in rest of the cases.
importjava.io.*;importjava.util.*;publicclassSolution{publicstaticvoidmain(String[]args){Scannerscan=newScanner(System.in);longn=scan.nextLong();longk=scan.nextLong();inta=(int)Math.pow(2,k);longcount=n/a;for(longi=3;Math.pow(i,k)<=n;i+=2){if(prime(i)){a=(int)Math.pow(i,k);count+=n/a;}}System.out.println(n-count);/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */}publicstaticbooleanprime(longn){if(n%2==0)returnfalse;for(inti=3;i*i<=n;i+=2){if(n%i==0)returnfalse;}returntrue;}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #193: Squarefree Numbers
You are viewing a single comment's thread. Return to all comments →
My code which is passing few test cases, gives wrong answer in few test cases and times out in rest of the cases.