UVA 294 求约数的个数

#include<iostream>
#include<string>
#include<string>
#include<string.h>
#include<stdio.h>
#include<queue>
#include<math.h>
#include<vector>
#include<stdlib.h>
#include<algorithm>
using namespace std;
long long primes[34000];
 int main(){
     memset(primes,0,sizeof(primes));
     primes[0]=2;
     long long t=1;int flag=1;
     for(long long i=3;i<34000;i++){
            flag=1;
        for(int j=2;j<=sqrt(i);j++){
            if(i%j==0){
                flag=0;
                break;
            }
        }
        if(flag) primes[t++]=i;
     }
     int a1;long long l,u,sum,maxn,k,x,r;
     cin>>r;
     while(r--){
        cin>>l>>u;
        sum=1;
        maxn=0;
        for(long long i=l;i<=u;i++){
            sum=1;x=i;flag=0;
           for(int j=0; j<t;j++){
            if(x%primes[j]==0){
                    a1=0;
                while(x%primes[j]==0){
                    a1++;
                    x=x/primes[j];

                }
                sum*=(a1+1);
            }
             if(x==1) break;
           }

            if(sum>maxn) {maxn=sum;k=i;}
        }
        printf("Between %lld and %lld, %lld has a maximum of %d divisors.\n",l,u,k,maxn);
     }


   return 0;
}

 

posted @ 2016-03-14 21:02  咸咸的告别  阅读(205)  评论(0编辑  收藏  举报