fork(2) download
  1. public class Main
  2. {
  3. public static void main(String args[])throws java.io.IOException
  4. {
  5. A ob=new A();
  6. ob.get();
  7. ob.display();
  8. }
  9. }
  10. class A
  11. {
  12. int T,i,B,X,n,nx,ct,k;
  13. String bnx,input[];
  14. java.util.ArrayList al,result;
  15. java.io.BufferedReader in=new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
  16. void get()throws java.io.IOException
  17. {
  18. T=Integer.parseInt(in.readLine());
  19. result=new java.util.ArrayList();
  20. for(i=0; i<T; i++)
  21. {
  22. getRemainingInputs();
  23. }
  24. }
  25. void getRemainingInputs()throws java.io.IOException
  26. {
  27. bnx=in.readLine();
  28. input=bnx.split(" ");
  29. B=Integer.parseInt(input[0]);
  30. X=Integer.parseInt(input[1]);
  31. calculate();
  32. }
  33. void calculate()
  34. {
  35. ct=0;
  36. for(n=1; n<=B; n++)
  37. {
  38. nx=n*X;
  39. findDivisors(nx);
  40. for(Object div: al)
  41. {
  42. if( (((Integer)div).intValue()>n) && (((Integer)div).intValue()<=B) )
  43. {
  44. ct=ct+1;
  45. break;
  46. }
  47. }
  48. }
  49. result.add(new Integer(ct));
  50. }
  51. void findDivisors(int nx)
  52. {
  53. al=new java.util.ArrayList();
  54. for(k=1; k<=nx; k++)
  55. {
  56. if(nx%k==0)
  57. {
  58. al.add(new Integer(k));
  59. }
  60. }
  61. }
  62. void display()
  63. {
  64. Object rs[]=result.toArray();
  65. for(int y=0; y<rs.length; y++)
  66. System.out.println(rs[y]);
  67. }
  68. }
  69.  
Success #stdin #stdout 0.08s 380160KB
stdin
3
5 1
10 3
100 6
stdout
0
5
63