#include <iostream>
using namespace std;
int main () {
int Primes[46340] = { 0 } ;
int runner = 0 ;
int chaser = 0 ;
int bound = 0 ;
int count = 0 ;
cin >> bound ;
if (bound == 2){
cout << "質數" ;
return 0;
}
if (runner < bound + 1 ) {
Primes[0] = 2;
count = 0;
for ( runner = 3 ; runner < bound +1 ; runner ++ ) {
for ( chaser = 0 ; Primes[chaser] != 0 ; chaser ++) {
if ( runner % Primes[chaser] == 0 ){
break;
}
if ( chaser == count ) {
count += 1;
Primes[count] = runner;
break;
}
}
}
}
if ( bound != Primes[count] ) {
cout << "非質數" ;
}
else if ( bound == Primes[count] ) {
cout << "質數" ;
}
return 0;
}
請各位幫我找一下盲點。Thanks A Lot!
#include
using namespace std;
int main () {
int Primes[46340] = { 0 } ;
int runner = 0 ;
int chaser = 0 ;
int bound = 0 ;
int count = 0 ;
cin >> bound ;
if (bound == 2){
cout << "質數" ;
return 0;
}
if (runner < bound + 1 ) {
Primes[0] = 2;
count = 0;
for ( runner = 3 ; runner < bound +1 ; runner ++ ) {
for ( chaser = 0 ; Primes[chaser] != 0 ; chaser ++) {
if ( runner % Primes[chaser] == 0 ){
break;
}
if ( chaser == count ) {
count += 1;
Primes[count] = runner;
break;
}
}
}
}
if ( bound != Primes[count] ) {
cout << "非質數" ;
}
else if ( bound == Primes[count] ) {
cout << "質數" ;
}
return 0;
}
請各位幫我找一下盲點。Thanks A Lot!
我不知道哪有盲點但我是這樣過的
#include <stdio.h>
#include <math.h>
int prime(int);
int main(void)
{
int n;
while(scanf("%d",&n)!=EOF)
{
if(prime(n))
printf("質數");
else
printf("非質數");
}
return 0;
}
int prime(int n)
{
int i;
double m;
m=sqrt(n);
if(n==1)
return 0;
for(i=2;i<=m;i++)
if((n%i)==0)
return 0;
return 1;
}