11606 - Factor Counter
raw download clone
C
views 31
,
size 778 b
#include <stdio.h>
#include <math.h>

int main(void)
{
    int t, l, r, d, ans;
    double sj;
    int div[20001] = {0};

    scanf("%d", &t);
    for(int i=1; i<=t; i++)
    {
        scanf("%d%d", &l, &r);
        ans = l;
        for(int j=l; j<=r; j++)
        {
            if(div[j] == 0)
            {
                d = 0;
                sj = sqrt(j);
                for(int k=1; k<=sj; k++)
                {
                    if(j % k == 0)
                        d++;
                }
                div[j] = 2 * d;
                if(sj - (int)sj == 0)
                    div[j] -= 1;
            }
            if(div[j] > div[ans])
                ans = j;
        }
        printf("%d\n", ans);
    }

    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.