:: ADVANCE ::

91일차 1. eratosthenes 본문

Algorithm/일일알고리즘

91일차 1. eratosthenes

KSJ14 2014. 10. 7. 15:15
반응형

[91.1] 16_75 eratosthenes

 

http://183.106.113.109/30stair/eratosthenes/eratosthenes.php?pname=eratosthenes

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
using namespace std;
 
int number[10000];
 
void makenum(int n)
{
    int i;
    for(i = 2; i <= n; i++)    {
        number[i] = i;
    }
    return ;
}
 
void eratosthenes(int n)
{
    int i, j;
 
    for(i = 2; i*i <= n; i++)    {
        for(j = 2; j <= n; j++)
        if(number[j] != i && number[j]%i == 0)    {
            number[j] = 0;
        }
    }
    return ;
}
 
int main(void)
{
    int n;
    cin >> n;
 
    makenum(n);
 
    eratosthenes(n);
 
    for(int i = 2; i <= n; i++)    {
        if(number[i] != 0)    {
            cout << number[i] << " ";
        }
    }
    cout << endl;
 
    return 0;
}
반응형

'Algorithm > 일일알고리즘' 카테고리의 다른 글

87일차 1. cross  (0) 2014.10.08
90일차 1. sprime  (0) 2014.10.08
86일차 1. ncpc_event  (0) 2014.10.02
85일차 1. ladder  (0) 2014.10.02
84일차 1. cryption  (0) 2014.09.30
Comments