Moderator: Board moderators

Thanks to shapnil.
sumonSUST
New poster

Posts: 5
Joined: Fri Oct 26, 2007 3:55 pm

Code: Select all
`        #include <iostream>       #include <sstream>       #include <string>        #include <cmath>       #include <algorithm>       #include <vector>       #include <cstdio>       using namespace std;       #define GI ({int _t; scanf("%d", &_t); _t;})       #define FOR(i, a, b) for (long long int i=a; i<b; i++)       #define REP(i, a) FOR(i, 0, a)       int main() {       int ca ;       cin>>ca;         while (ca--) {             long  int res = -1, max = -1;             long  int a, b;             cin >> a >> b;             if (a==1 && b==1) {                printf("Between 1 and 1, 1 has a maximum of 1 divisors.\n");                continue;             }             FOR(i, a, b+1) {                int t = 0;                FOR(j, 1, sqrt(i)) {                   if (i%j==0) t++;                }                t*=2;                if (sqrt(i)*sqrt(i) == i) t++;                if (t >max ) {                   res = i; max = t;                }             }             printf("Between %lld and %lld, %lld has a maximum of %lld divisors.", a, b, res, max);             if(ca>0)cout<<endl;          }          return 0;       }`
Eather
New poster

Posts: 28
Joined: Thu Jan 28, 2010 2:23 pm

A better approach to solve this problem should be using prime divisor. If you can find that a number N = (a^x)*(b^y)*(c^z) where a, b, c are prime number then the number of divisor of N should be (x+1)*(y+1)*(Z+1).

If you have already solve 583 (prime factor) then it will be easier for you to solve this problem.
Code: Select all
`int divisors (long int c) {      long int s;      int i, j, flag;      int divisornum = 1;      i = 0;      flag = 0;      for(j=0;j<k;j++)      {         factor[j] = 0;      }      k = 0;      if(c<0)      {         c = - c;      }      s = sqrt(c);      while((c>=prime[i] && prime[i]<=s) && c!=1) //prime is an array which hold the prime number      {         j = 0;         while((c%prime[i])==0)         {            flag = 1;            c = c/prime[i];            j++;         }         if(flag==1)         {            factor[k] = j;    //save the power of a prime factor to another array            k++;         }         flag = 0;               i++;      }      if(c>1)      {         factor[k] = 1;         k++;      }      for(j=0;j<k;j++)      {         divisornum = divisornum * (factor[j]+1);        //applying the process which I describe earlier      }      return divisornum;}`

first done the seive code and find out prime number upto 56000 (approximately). Then use this code for finding number of divisor.
Kamarul Kawnayeen
New poster

Posts: 2
Joined: Wed Feb 02, 2011 10:10 pm

my code:
#include<stdio.h>
#include<math.h>
int main()
{
long long t,l,u,i,rem,sq,j,d=0,max,temp,swap;
scanf("%lld",&t);
while(t--)
{
d=0;
max=0;
scanf("%lld %lld",&l,&u);
if(l>u)
{
swap=l;
l=u;
u=swap;
}
for(i=l;i<=u;i++)
{
rem=i,d=0;
sq=sqrt(rem);
for(j=2;j<=sq;j++)
{
if(rem%j==0)
d++;
if(sq*sq==rem)
d--;
}
if(max<d)
{
max=d;
temp=rem;
}

}
max=max*2;
max=max+2;
printf("Between %lld and %lld, %lld has a maximum of %lld divisors.\n",l,u,temp,max);

}
return 0;
}
sumit saha shawon
New poster

Posts: 19
Joined: Tue Jun 26, 2012 9:19 pm

sumit saha shawon
New poster

Posts: 19
Joined: Tue Jun 26, 2012 9:19 pm

Try the input little joey posted in this thread.
brianfry713
Guru

Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Thanks.
sophi
New poster

Posts: 6
Joined: Tue Aug 14, 2012 6:00 pm

brianfry713
Guru

Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

input
Code: Select all
`51 01 12 23 312 18`

output
Code: Select all
`Between 1 and 1, 0 has a maximum of 2 divisors.Between 1 and 1, 1 has a maximum of 1 divisors.Between 2 and 2, 2 has a maximum of 2 divisors.Between 3 and 3, 3 has a maximum of 2 divisors.Between 12 and 18, 12 has a maximum of 6 divisors.`
Nothing is imposible in the world.....And
Never Judge a Book by Its Cover.............
BUBT HIDDEN
http://uhunt.felix-halim.net/id/168573
http://shipuahamed.blogspot.com
shipu_a
New poster

Posts: 22
Joined: Tue Oct 23, 2012 8:04 pm