Hope it Helps
Keep posting !!
![:D](./images/smilies/icon_biggrin.gif)
Moderator: Board moderators
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 notbecause judge is down
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;
}
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;
};
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.