fork(17) download
  1. // Created by akashbhalotia
  2. import java.io.*;
  3. import java.util.*;
  4. class C
  5. {
  6. public static void main(String[] args) throws IOException
  7. {
  8.  
  9. int i,N,A,B,count,lo,hi,max,sqrt=(int)Math.sqrt(1000000000);
  10. long square;
  11.  
  12. HashMap<Integer,Integer> map=new HashMap<>();
  13. ArrayList<Integer> arr=new ArrayList<>();
  14. arr.add(1);
  15. map.put(1,0);
  16.  
  17. for(i=2;i<=sqrt;i++)
  18. {
  19. if(!map.containsKey(i))
  20. {
  21. arr.add(i);
  22. map.put(i, 0);
  23. square=i;
  24. square*=square;
  25. count=1;
  26.  
  27. while(square<=1000000000)
  28. {
  29. map.put((int)square,count++);
  30. arr.add((int)square);
  31. square*=square;
  32. }
  33. }
  34. }
  35.  
  36. Collections.sort(arr);
  37. int a[]=new int[arr.size()];
  38.  
  39. for(i=0;i<arr.size();i++)
  40. a[i]=arr.get(i);
  41.  
  42. int T=Integer.parseInt(br.readLine().trim());
  43. StringBuilder sb=new StringBuilder();
  44.  
  45. while(T-->0)
  46. {
  47. max=0;
  48.  
  49. String s[]=br.readLine().trim().split(" ");
  50. A=Integer.parseInt(s[0]);
  51. B=Integer.parseInt(s[1]);
  52.  
  53. lo=(int)Math.sqrt(A);
  54. hi=(int)Math.sqrt(B);
  55.  
  56. if(lo*lo<A)
  57. lo++;
  58.  
  59. lo*=lo;
  60. hi*=hi;
  61.  
  62. lo=Arrays.binarySearch(a,lo);
  63. hi=Arrays.binarySearch(a,hi);
  64.  
  65. for(i=lo;i<=hi;i++)
  66. max=Math.max(max,map.get(a[i]));
  67.  
  68. sb.append(max).append("\n");
  69. }
  70. System.out.println(sb);
  71. }
  72. }
Success #stdin #stdout 0.16s 2184192KB
stdin
3
10 20
6000 7000
2 1000000000
stdout
2
3
4