#54156: c language 程式碼


andytank337@gmail.com (bluesquid29)


```c

#include <stdio.h>
#include <math.h> // sqrt(n)
 
int countDivisors(int n) 
{
    int count = 0;
    int sqrtN = (int)sqrt(n);
    
    for (int i = 1; i <= sqrtN; i++) {
        if (n % i == 0) 
{
            count++;
            if (i != n / i) 
{
                count++;
            }
        }
    }
    return count;
}
 
int main(void) 
{
    int N, L, U;
    
    scanf("%d", &N);
    
    while (N--) 
{
        scanf("%d %d", &L, &U);
        
        int maxDivisors = 0;
        int numWithMaxDivisors = L;
        
        for (int i = L; i <= U; i++) 
{
            int divisors = countDivisors(i);
            if (divisors > maxDivisors) 
{
                maxDivisors = divisors;
                numWithMaxDivisors = i;
            }
        }
        
        printf("Between %d and %d, %d has a maximum of %d divisors.\n", 
               L, U, numWithMaxDivisors, maxDivisors);
    }
    
    return 0;
}
```