294  Divisors
Moderator: Board moderators
 Ghust_omega
 Experienced poster
 Posts: 115
 Joined: Tue Apr 06, 2004 7:04 pm
 Location: Venezuela

 New poster
 Posts: 22
 Joined: Fri Jan 17, 2003 8:24 am
Re: Cul de sac.
Today i try to using sqrt() like find the prime number
100 = 10 * 10
it's impossible divide the number large than 10 in this case. So you can add the range below than sqrt().
and then do this :
if (number%divisor==0){
Counter++;
if (number/divisor!=divisor)Counter++;
}
that so solve like 2*50 and no need to found 50*2 because our limit is 10.
i dunno this algorithm is acceptable or not because judge is down
100 = 10 * 10
it's impossible divide the number large than 10 in this case. So you can add the range below than sqrt().
and then do this :
if (number%divisor==0){
Counter++;
if (number/divisor!=divisor)Counter++;
}
that so solve like 2*50 and no need to found 50*2 because our limit is 10.
i dunno this algorithm is acceptable or not because judge is down

 New poster
 Posts: 22
 Joined: Fri Jan 17, 2003 8:24 am
Re: Cul de sac.
All i say is correct i acceptablejhonny_yang wrote:Today i try to using sqrt() like find the prime number
100 = 10 * 10
it's impossible divide the number large than 10 in this case. So you can add the range below than sqrt().
and then do this :
if (number%divisor==0){
Counter++;
if (number/divisor!=divisor)Counter++;
}
that so solve like 2*50 and no need to found 50*2 because our limit is 10.
i dunno this algorithm is acceptable or not because judge is down
294:DIVISORS...RUNTIME ERROR...PLEASE HELP!!!!!!!
I got runtime error. Please help me.
I have precalculated prime numbers. Then computed the divisors for n where n =p1^e1* p2^e2* ... *pn^en equals (e1+1)*(e2+1)*...*(en+1).
I have precalculated prime numbers. Then computed the divisors for n where n =p1^e1* p2^e2* ... *pn^en equals (e1+1)*(e2+1)*...*(en+1).
Code: Select all
#include<math.h>
#include<stdio.h>
int Isprime(int I);
int primes[10000]={2};
long double lu;
unsigned long max,sum,j,p,N,d,LU,pm=1,i,U,L;
void main()
{
lu=sqrt(1000000000);
LU=lu;
for(p=0,i=3;i<=LU;i+=2)
if(Isprime(i)) primes[pm++]=i;
scanf("%lu",&N);
while(N>0)
{
max=0;
scanf("%lu%lu",&L,&U);
{
for(i=L;i<=U;i++)
{
d=1;
if(i==1) d=1;
pm=0;j=i;
while(j!=1)
{
sum=0;
while(j%primes[pm]==0)
{
j=j/primes[pm];
sum++;
}
pm++;
if(sum>0) d=d*(sum+1);
}
if(d>max){
max=d;
p=i;
}
}
}
printf("Between %lu and %lu, %lu has a maximum of %lu divisors.\n",L,U,p,max);
N;
}
}
int Isprime(int I)
{
int n;
for(n=2;n<I;n++)
if((I%n)==0) return 0;
return 1;
}

 New poster
 Posts: 11
 Joined: Sun Jan 02, 2005 9:14 am
 alu_mathics
 Learning poster
 Posts: 55
 Joined: Sat Jan 24, 2004 9:30 pm
 Location: Chittagong
 Contact:

 Experienced poster
 Posts: 131
 Joined: Sat Jul 17, 2004 4:09 am
 Location: Lima, Per
294  Divisors WA!!!
Here is my code. I don't know what is wrong with it. Please help.
Code: Select all
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int N, L, H, P = 0, D = 0;
double nesto;
int divisors = 0;
cin >> N;
for(int i = 0; i < N; i++)
{
cin >> L >> H;
for(int j = L; j <= H; j++)
{
divisors = 0;
nesto = sqrt(j);
for(int l = 1; l <= nesto; l++)
{
if(!(j%l))
divisors += 2;
if(nesto * nesto == j)
divisors;
};
if(D < divisors)
{
D = divisors;
P = j;
}
};
cout << "Between " << L << " and " << H << ", " << P << " has a maximum of " << D <<" divisors." << endl;
D = 0;
};
return 0;
};
Divisors294 WA
I have tested it many times,but it still got WA, please help me
Code: Select all
program divisor294;
var n,i,l,k,temp,m,o,p,max,kand,a,j,t:longword;
begin
readln(k);
for j:=1 to k do
begin
readln(m,o);
kand:=m;
max:=0;
for a:=m to o do
begin
t:=0;
temp:=1;
n:=a;
l:=round(sqrt(n));
while n mod 2=0 do
begin
n:=n shr 1;
inc(t);
end;
temp:=temp*(t+1);
i:=3;
t:=0;
while (n>1) do
begin
if i>l then break;
if (n mod i=0) then
begin
n:=n div i;
inc(t);
end;
if (n mod i<>0) then
begin
temp:=temp*(t+1);
inc(i,2);
t:=0;
end;
end;
if (temp=1) then temp:=2;
if temp>max then
begin
max:=temp;
kand:=a;
end;
if kand=1 then max:=1;
end;
writeln('Between ',m,' and ',o,', ',kand,' has a maximum of ',max,' divisors.');
end;
end.