fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. public class Main
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13.  
  14. String s[]=inp.readLine().split(" ");
  15. int a=Integer.parseInt(s[0]);
  16. int b=Integer.parseInt(s[1]);
  17.  
  18. if(a<b)
  19. System.out.println(0);
  20. else if(a==b)
  21. System.out.println("infinity");
  22. else
  23. {
  24.  
  25. int count=0;
  26. for(int i=2;i*i<=a-b;i++)
  27. {
  28. if((a-b)%i==0)
  29. {
  30. if(i>b)
  31. count++;
  32. if(((a-b)/i)>b && (i*i!=a-b))
  33. count++;
  34. }
  35. }
  36. if(b==0 && a==1)
  37. {
  38. count=count+1;
  39. System.out.println(count);
  40. return;
  41. }
  42. else if(b==0 && a!=1)
  43. System.out.println(count+2);
  44. else if(b<a-b)
  45. System.out.println(count+1);
  46. else if(b>a-b)
  47. System.out.println(count);
  48. }
  49. }
  50. }
Success #stdin #stdout 0.07s 380224KB
stdin
21 5
stdout
2