fork(3) download
  1. #include<stdio.h>
  2. #include<math.h>
  3. int divisor(int n)
  4. {
  5. int i,div;
  6. double sqrtn;
  7. if(n==1)
  8. return 1;
  9. else if(n==2)
  10. return 2;
  11. else{
  12. div=2;
  13. sqrtn=sqrt(n);
  14. for(i=2;i<sqrtn;i++)
  15. {
  16. if(n%i==0)
  17. {
  18. div=div+2;
  19. }
  20. }
  21. if(sqrtn*sqrtn==n)
  22. div++;
  23. return div;
  24. }
  25. }
  26.  
  27. int main() {
  28. int n,div,max=0,U,L,T,a=1,maxn;
  29. scanf("%d",&T);
  30. while(a<=T)
  31. {
  32.  
  33. scanf("%d %d",&L,&U);
  34. max=0;
  35.  
  36. for(n=L;n<=U;n++)
  37. {
  38. div=divisor(n);
  39.  
  40. if(div>max){
  41. maxn=n;
  42. max=div;
  43. }
  44. }
  45. printf("Between %d and %d, %d has a maximum of %d divisors.\n",L,U,maxn,max);
  46. a++;
  47. }
  48. return 0;
  49. }
  50.  
Success #stdin #stdout 0.08s 2252KB
stdin
3
1 10
1000 1000
999999900 1000000000
stdout
Between 1 and 10, 6 has a maximum of 5 divisors.
Between 1000 and 1000, 1000 has a maximum of 17 divisors.
Between 999999900 and 1000000000, 999999924 has a maximum of 193 divisors.