Int main () {
Int n, y;
The scanf (" % d ", & amp; N);
Y=0;
for(int i=2; i<=n; I++) {
For (int t=2; t<=I; T++) {
If (I % t==0) {
Y=y + 1;
}
If (y==1) {
Printf (" % d \ n ", I);
}
}
}
}
CodePudding user response:
# include
Int main ()
{
Int n, y;
The scanf (" % d ", & amp; N);
for(int i=2; i<=n; I++)
{
Y=0;//y in here, each number after traversal, you need to reset y
For (int t=2; t<=I; T++)
{
If (I % t==0)
{
Y=y + 1;
If (y>=1)//in addition to 1, more than one factor, is can't be prime, improve the efficiency of
{
break;
}
}
If (y==1)
{
Printf (" % d \ n ", I);
}
}
}
}
CodePudding user response:
Shake his hand,,, small mistake# include
Int main ()
{
Int n, y;
The scanf (" % d ", & amp; N);
for(int i=2; i<=n; I++)
{
Y=0;//y in here, each number after traversal, you need to reset y
For (int t=2; t<=I; T++)
{
If (I % t==0)
{
Y=y + 1;
If (y> 1)//in addition to 1, more than one factor, is can't be prime, improve the efficiency of
{
break;
}
}
If (y==1)
{
Printf (" % d \ n ", I);
}
}
}
}
CodePudding user response:
Wrong, wrong, the result of the operation, andCodePudding user response:
Title is like this:CodePudding user response:
Uh...int n, y;
The scanf (" % d ", & amp; N);
for(int i=2; i<=n; I++)
{
Y=0;//y in here, each number after traversal, you need to reset y
For (int t=2; t<=I; T++)
{
If (I % t==0)
{
Y=y + 1;
}
If (y> 1)//in addition to 1, more than one factor, is can't be prime, improve the efficiency of
{
break;
}
}
If (y==1)
{
Printf (" % d \ n ", I);
}
}