Home > Back-end >  Write a program for the given positive integer m less than the sum of a prime number.
Write a program for the given positive integer m less than the sum of a prime number.

Time:09-24

Write a program for the given positive integer m within the sum of a prime number,

CodePudding user response:

Send technical area, otherwise people can't see,

CodePudding user response:

Many methods, if m is prime sieve method can be used for prime
M large loop only judge whether a prime, then sum

CodePudding user response:

Erichsen sieve method
# include
# define ll long long
using namespace std;
E5 const int maxn=1 + 5;
Int vis [maxn];
Int main () {
Int j, ans=0;
The scanf (" % d ", & amp; M);
For (int I=2; i<=m; + + I) {
If (vis [I]==0) ans +=I;
For (int j=I + I; j<=m; J +=I)
Vis [j]=1;
}
Printf (" % d \ n ", ans);
return 0;
}
  • Related