首页 > 代码库 > uva294

uva294

题目连接:UVA - 294

 1 #include<cstdio>
 2 int L,R;
 3 int cnt;
 4 int pri[1010];
 5 int vis[1010];
 6 void is_pri()
 7 {
 8     cnt=0;
 9     for(int i=3;i<35;i++) if(!vis[i])
10         for(int j=i*i;j<1010;j+=i)
11             vis[j]=1;
12     for(int i=2;i<1010;i++) if(!vis[i])
13         pri[cnt++]=i;
14 }
15 
16 int divisor(int x)
17 {
18     int r=1;
19     for(int i=0;i<cnt;i++)
20     {
21         int tmp=1;
22         while(x%pri[i]==0) {tmp++;x/=pri[i];}
23         r*=tmp;
24         if(x==1) break;
25     }
26     return r;
27 }
28 int main()
29 {
30     is_pri();
31     int t;
32     scanf("%d",&t);
33     while(t--)
34     {
35         int ans=-1;
36         int res;
37         scanf("%d%d",&L,&R);
38         for(int i=L;i<=R;i++)
39         {
40            int temp=divisor(i);
41            if(temp>ans)
42            {
43                ans=temp;
44                res=i;
45            }
46         }
47         printf("Between %d and %d, %d has a maximum of %d divisors.\n",L,R,res,ans);
48 
49     }
50 }

 

uva294