Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<math.h>
- int isprime(int n){
- if(n < 5 || n%2 == 0 || n%3 == 0)
- return (n == 2 || n == 3);
- int maxp = sqrt(n) + 2;
- int p;
- for(p = 5; p < maxp; p+= 6){
- if(n%p == 0 || n % (p+2) == 0) return 0;
- }
- return 1;
- }
- int main(){
- int N,n;
- int L,U,D,P;
- int i,j,s;
- int count;
- int maxp, p;
- int acc;
- scanf("%d", &N);
- for(n = 0; n < N; n++){
- scanf("%d%d", &L, &U);
- D = 0;
- for(i = L; i <= U; i++){
- count = 0;
- acc = 1;
- j = i;
- for(; j%2 == 0; j/=2)
- count++;
- acc *= count+1;
- j = i;
- count = 0;
- for(; j%3 == 0; j/=3)
- count++;
- acc *= count+1;
- maxp = sqrt(i) + 2;
- for(p = 5; p < maxp; p++){
- if(isprime(p)){
- count = 0;
- j = i;
- for(; j%p == 0; j/=p)
- count++;
- acc *= count+1;
- }
- }
- if(acc > D){
- D = acc;
- P = i;
- }
- }
- printf("Between %d and %d, %d has a maximum of %d divisors.\n",L, U, P, D);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement