首页 > 代码库 > 素数---小修改2

素数---小修改2

 

 

 

 

#include<stdio.h>int main(){    int n,a,b,i;    int sum=0   ;    scanf("%d%d",&a,&b);    {        for (n=a;n<=b;n++)        {            for (i=2;i<=n-1;i++)                if (n%i==0) break;            if (i>=n)                sum+=n;        }        printf("%d",sum);        printf("\n");    }}
View Code

#include<stdio.h>
int main()
{
int n,a,b,i;
int sum=0 ;

scanf("%d%d",&a,&b);
{
for (n=a;n<=b;n++)
{
for (i=2;i<=n-1;i++)
if (n%i==0) break;
if (i>=n)


sum+=n;
}
printf("%d",sum);
printf("\n");
}
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

#include<stdio.h>int main(){    int n,a,b,i;    int sum=0   ;    while ( scanf("%d%d",&a,&b)==2)    {        for (n=a;n<=b;n++)        {            for (i=2;i<=n-1;i++)                if (n%i==0) break;            if (i>=n)                sum+=n;        }        printf("%d",sum);        printf("\n");    }}
View Code

#include<stdio.h>
int main()
{
int n,a,b,i;
int sum=0 ;

while ( scanf("%d%d",&a,&b)==2)
{
for (n=a;n<=b;n++)
{
for (i=2;i<=n-1;i++)
if (n%i==0) break;
if (i>=n)


sum+=n;
}
printf("%d",sum);
printf("\n");
}
}

 

 

 

 

 

 

 

 

****************************************************************************************************************************************

 

 

#include<stdio.h>int main(){    int n,a,b,i;    int j,s;    int c[1000];  while ( scanf("%d%d",&a,&b)==2)    {        j=0;        for (n=a;n<=b;n++)        {            for (i=2;i<=n-1;i++)                if (n%i==0) break;            if (i>=n)                            c[j++]=n;                   }                        s=0;        for (i=0;i<j;i++)            s=s+c[i];        printf("%d\n",s);    }    return 0;}
View Code

#include<stdio.h>
int main()
{
int n,a,b,i;
int j,s;
int c[1000];
while ( scanf("%d%d",&a,&b)==2)
{
j=0;
for (n=a;n<=b;n++)
{
for (i=2;i<=n-1;i++)
if (n%i==0) break;
if (i>=n)

c[j++]=n;

}


s=0;
for (i=0;i<j;i++)
s=s+c[i];
printf("%d\n",s);
}
return 0;
}