by yahoo » Sat Nov 23, 2002 8:46 pm
I have used brute force method to solve this but getting runtime error all the time.Can anybody please explain why i am getting runtime error.
Here is my code:
#include <stdio.h>
#include <math.h>
main()
{
long long int i,j,hi,lo,r,a[100000],pr,cnt,n=0,flag,num;
double count;
for(i=2;i<10000;i++)
{
for(j=2;j<=i/2;j++)
if(!(i%j))
break;
if(j<=i/2);else a[n++]=i;
}
while(1)
{
r=scanf("%lld%lld",&hi,&lo);
if(r==EOF) break;
cnt=0;
for(i=hi;i<=lo;i++)
{
pr=i*i+i+41;
j=flag=0;
while(1)
{
if(pr%a[j]==0) {flag=1;break;}
if(a[j]>pr/2) break;
j++;
}
if(!flag) cnt++;
}
num=lo-hi+1;
count=((float)cnt)/num*100;
printf("%.2lf\n",count);
}
return 0;
}