Posted: Sun Mar 11, 2007 4:07 pm
so why dont you remove your code from the forum?
best of luck.
best of luck.
Code: Select all
GOT AC...
Code: Select all
1
3 3
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;
}
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.
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;
}
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;
}
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;
}
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;
}