Created
March 4, 2020 04:38
-
-
Save NoharaMasato/428a38122b73b2c8e079c1e801d2e263 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
#define MAX_N 100000001 | |
int prime[MAX_N]; | |
bool is_prime[MAX_N + 1]; | |
int sieve(int n) { | |
int p = 0; | |
for (int i(0);i<=n;i++) is_prime[i] = true; | |
is_prime[0] = is_prime[1] = false; | |
for (int i(2);i<=n;i++){ | |
if (is_prime[i]){ | |
cout << i << ","; | |
prime[p++] = i; | |
for (int j(2*i);j<=n;j+=i) is_prime[j] = false; | |
} | |
} | |
cout << endl; | |
return p; | |
} | |
int main(){ | |
int N = 100000000; | |
cout << N << "以下の素数を列挙" << endl; | |
int cnt = sieve(N); | |
cout << N << "以下の素数の個数:" << cnt << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment