294 please help me

All about problems in Volume II. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Postby sumonSUST » Fri Nov 02, 2007 2:56 pm

Thanks to shapnil.
sumonSUST
New poster
 
Posts: 5
Joined: Fri Oct 26, 2007 3:55 pm

Re: 294 please help me

Postby Eather » Sat Dec 18, 2010 5:28 am

Im getting Wrong Answer in this problem, Please help me....
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

Re: 294 please help me

Postby Kamarul Kawnayeen » Wed Feb 02, 2011 10:26 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

Re: 294 please help me

Postby sumit saha shawon » Tue Jul 10, 2012 7:00 pm

my output is ok but I am getting wa.please help me to find my bug
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

Re: 294 please help me

Postby sumit saha shawon » Sat Jul 14, 2012 2:24 pm

I am asking for help but no one helping me.please help me :oops:
sumit saha shawon
New poster
 
Posts: 19
Joined: Tue Jun 26, 2012 9:19 pm

Re: 294 please help me

Postby brianfry713 » Tue Jul 17, 2012 12:32 am

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

Re: 294 please help me

Postby sophi » Thu Sep 27, 2012 6:17 pm

Please Help me providing Sample I/O. I'm getting WA but can't figure it out
Thanks.
sophi
New poster
 
Posts: 6
Joined: Tue Aug 14, 2012 6:00 pm

Re: 294 please help me

Postby brianfry713 » Thu Sep 27, 2012 10:46 pm

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

294 please help me

Postby shipu_a » Thu Mar 28, 2013 7:27 pm

input
Code: Select all
5
1 0
1 1
2 2
3 3
12 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
Location: Dhaka,Bangladesh

Previous

Return to Volume II

Who is online

Users browsing this forum: No registered users and 1 guest