fork(1) download
  1. import java.io.BufferedReader;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5.  
  6. /**
  7.  * Created by hardCode on 4/8/2017.
  8.  */
  9. class MonkAndAtm {
  10. static final int MAX=10000001;
  11.  
  12. static int smallestFacctor[]=new int[MAX];
  13.  
  14. public static void main(String[] args) throws IOException {
  15. //BufferedReader br=new BufferedReader(new FileReader("input.txt"));
  16. int t,n;
  17.  
  18. t=Integer.parseInt(br.readLine());
  19. initFactors();
  20.  
  21. StringBuilder sbr=new StringBuilder();
  22. while (t-- > 0) {
  23.  
  24. n=Integer.parseInt(br.readLine());
  25. //System.out.println("stuck at "+n);
  26. sbr.append(solve(n) + "\n");
  27. //System.out.println(solve(n));
  28. }
  29. System.out.print(sbr.toString());
  30.  
  31.  
  32. }
  33.  
  34. private static int solve(int n) {
  35.  
  36. int sqrt= (int) Math.sqrt(n);
  37.  
  38. int ans=Integer.MIN_VALUE;
  39. for (int m =1; m<=sqrt ; m++) {
  40. if (n%m==0)
  41. {
  42. int x=n/m;
  43. //System.out.println(smallestFacctor[x]);
  44. int temp=countFactors(x);
  45.  
  46. if (isPowerOf2(temp))
  47. ans=Integer.max(temp,ans);
  48.  
  49. temp=countFactors(m);
  50. if (isPowerOf2(temp))
  51. ans=Integer.max(temp,ans);
  52. }
  53. }
  54.  
  55. return ans;
  56. }
  57.  
  58. public static int countFactors(int n) {
  59. int m=n,count=0,ans=1;
  60.  
  61. while (n>1){
  62. count=0;
  63. int x= smallestFacctor[n];
  64. //System.out.println(n+" "+x+" "+(n%x==0));
  65. //System.out.println("s factor "+n+" "+x);
  66. while (n%x==0){
  67. count++;
  68. n/=x;
  69. }
  70. ans*=(count+1);
  71. }
  72. return ans;
  73. }
  74.  
  75.  
  76. public static boolean isPowerOf2(int n) {
  77. if (n==1)
  78. return true;
  79.  
  80. if ((n&1)==1 || n==0)
  81. return false;
  82.  
  83. return isPowerOf2(n >> 1);
  84. }
  85.  
  86. private static void initFactors() {
  87.  
  88. for (int i = 2; i < MAX; i+=2) {
  89. smallestFacctor[i]=2;
  90. }
  91. smallestFacctor[0]=1;
  92. smallestFacctor[1]=1;
  93.  
  94. int sqrt= (int) Math.sqrt(MAX);
  95.  
  96. for (int i = 3; i <MAX; i+=2) {
  97.  
  98. if (smallestFacctor[i]==0){
  99.  
  100. smallestFacctor[i]=i;
  101.  
  102. if ((long)i*i<MAX)
  103. for (int j =i*i; j <MAX ; j+=2*i) {
  104. if (smallestFacctor[j]==0)
  105. smallestFacctor[j]=i;
  106. }
  107. }
  108. }
  109.  
  110. }
  111. }
  112.  
Success #stdin #stdout 0.14s 4386816KB
stdin
3
15
48
60
stdout
4
8
8