This problem requires the statistics given integer number of prime numbers N and M within the interval and summing them.
Input format:
Input give two positive integers M and N (1≤M≤N≤500) in a row.
Output format:
sequentially outputting the number of prime numbers N M and the interval in a row and separated by a space between them and digital.
Sample input:
1031
Sample output:
7143
Problem with the first code:
Correct code:
// Date:2020/3/18
// Author:xiezhg5
#include <stdio.h>
#include <math.h>
int main(void)
{
int k;
int i;
int j;
int count=0;
int sum=0;
int m,n;
scanf("%d %d",&m,&n);
for(i=m;i<=n;i++)
{
k=sqrt(i);
for(j=2;j<=k;j++)
if(i%j==0)
{
break;
}
if(j>=k+1)
{
if(i==1)
count=count;
else
{
sum=sum+i;
count++;
}
}
}
printf("%d %d\n",count,sum);
return 0;
}
The reference code is as follows:
#include <stdio.h>
#include <stdio.h>
void main()
{
int m,k,i,n=0;
for(m=101;m<=200;m=m+2)
{
k=sqrt(m);
for(i=2;i<=k;i++)
if(m%i==0)
break;
if(i>=k+1)
{
print("%d",m);
n=n+1;
}
if(n%10==0)
printf("\n");
}
printf("\n");
}