294 - Divisors

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

Moderator: Board moderators

User avatar
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Post by newton » Sun Mar 11, 2007 4:07 pm

so why dont you remove your code from the forum?




best of luck.

hamedv
Learning poster
Posts: 98
Joined: Mon May 07, 2007 8:30 am

Post by hamedv » Wed Jun 20, 2007 4:35 pm

What's wrong whit my code?!!

Code: Select all

GOT AC...
Last edited by hamedv on Mon Jul 02, 2007 8:45 am, edited 1 time in total.

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Post by helloneo » Wed Jun 20, 2007 5:20 pm

Try this case..

Code: Select all

1
3 3

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

Post by sumonSUST » Fri Nov 02, 2007 2:19 pm

plz help me.

Code: Select all

#include<stdio.h>
#include<math.h>

int main()
{
	long  i,j,x,val,temp=0,count,num,a,b,test,temp1;
	
	scanf("%ld",&test);
	
	while(test--)
		{
	
	      scanf("%ld%ld",&a,&b);
			
		  if(a>b)
		  {
			temp1=a;
			a=b;
			b=temp1;
		  }
		  
		 
		  
		for(i=a;i<=b;i++)
		{
	     	count=0;
			
		   x=(long)sqrt(i);
		

		for(j=1;j<=x;j++)
		{
			if(i%j==0)
				++count;
		}

		if(x*x==i)
          val=2*count-1;
		else
			val=2*count;


		if(val>temp)
		{
			temp=val;
			num=i;
		}
	}

	printf("Between %ld and %ld, %ld has a maximum of %ld divisors.\n",a,b,num,temp);
      
	}
 return 0;
}

sapnil
Experienced poster
Posts: 106
Joined: Thu Apr 26, 2007 2:40 pm
Location: CSE-SUST
Contact:

Post by sapnil » Fri Nov 02, 2007 2:46 pm

To sumon

Try with this case:

Code: Select all

input:
2
15 16
1 1
output:
Between 15 and 16, 16 has a maximum of 5 divisors.
Between 1 and 1, 1 has a maximum of 1 divisors.
Thanks
Keep posting
Sapnil
"Dream Is The Key To Success"

@@@ Jony @@@

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

Post by sumonSUST » Fri Nov 02, 2007 2:56 pm

Thanks to shapnil.

mahedee
New poster
Posts: 3
Joined: Sun Mar 23, 2008 1:29 pm
Contact:

294-Divisors #RTE. Please help

Post by mahedee » Mon Jul 21, 2008 12:28 pm

I could not understand why is it runtime error. Please help me.

Code: Select all

/*Run Time error.*/

#include<stdio.h>
#define n 400000

long long prime[n];

long long prime_factor(long m)
{

	long long i,j,fact,div,sum;
	div = 1;
	sum =0;
	j = i = 2;
	fact = m;
	while(1)
	{
		if(i>j)
		{
			div = div*(sum+1);
			if(fact==1) break;
			sum = 0;
			j = i;
		}
		if(prime[i]==1&&fact%i==0)
		{
			sum++;
			fact = fact/i;
			continue;
		}
		i++;
	}
	return div;
}

long long prime_sieve()
{
	long long i,j;
	for(i = 2; i < n; i++)
		prime[i] = 1;
	for(i = 2; i <n ; i++)
	{
		if(prime[i])
		{
			for( j = i; j <= n/i; j++)
				prime[i*j] = 0;
		}
	}
	return 0;
}

int main()
{

	long long i,k,num,L,U,max,max_val,div;

	prime_sieve();
	while(scanf("%lld",&num)==1)
	{
		for( i = 1; i <= num; i++)
		{
			scanf("%lld%lld",&L,&U);
			max = 0; max_val = L;
			for(k = L; k<=U; k++)
			{
				div = prime_factor(k);
				if(div>max)
				{
					max = div;
					max_val = k;
				}
			}
			printf("Between %lld and %lld, %lld has a maximum of %lld divisors.\n",L,U,max_val,max);
		}
	}
	return 0;
}
Mahedee

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 294-Divisors #RTE. Please help

Post by sohel » Tue Jul 22, 2008 7:44 am

Don't create a new thread for a problem that already exists.
There are other threads relating to this problem '294'. Please use an existing thread.

Eather
New poster
Posts: 28
Joined: Thu Jan 28, 2010 2:23 pm

294: Wrong Answer...

Post by Eather » Fri Dec 17, 2010 11:23 am

I dont know why im getting WA...??

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;
   }
Please help me... :(

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 294: Wrong Answer...

Post by sohel » Fri Dec 17, 2010 5:37 pm

Have you gone through the existing discussions - http://acm.uva.es/board/viewtopic.php?f=2&t=3875?
Don't create a new thread for a problem that already exists!

Eather
New poster
Posts: 28
Joined: Thu Jan 28, 2010 2:23 pm

Re: 294: Wrong Answer...

Post by Eather » Sat Dec 18, 2010 5:24 am

sorry via, i didnt find any post except one of yours... and that was locked.. so i did it..

Eather
New poster
Posts: 28
Joined: Thu Jan 28, 2010 2:23 pm

Re: 294 please help me

Post by 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;
       }

Kamarul Kawnayeen
New poster
Posts: 2
Joined: Wed Feb 02, 2011 10:10 pm
Contact:

Re: 294 please help me

Post by 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.

sumit saha shawon
New poster
Posts: 19
Joined: Tue Jun 26, 2012 9:19 pm

Re: 294 please help me

Post by 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

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

I am asking for help but no one helping me.please help me :oops:

Post Reply

Return to “Volume 2 (200-299)”