1~20의 최소공배수 구하는 걸 STL 공부하는 김에 한번 만들어볼려고 했는데

씨부럴 것이 디버깅을 해도 알고리즘 헤더파일을 까서 보여주질 않나


제 수명좀 늘려주이소





#include <iostream>

#include <stdio.h>

#include <math.h>

#include <algorithm>

#include <vector>

#include <functional>

#include <windows.h>


int it_value;


bool IsNotPrime(int i, int j);

bool IsDividable(int i, int j);

void main()

{

std::vector<int> Prime;

std::vector<int> Num;

std::vector<int> Count;

int count;

int lenght;

int ans=1;


std::cin >> lenght;


for (int i = 1; 1 < lenght; i++)

{

Prime.push_back(i);//TODO: Pushback 이 빠른지, 일반 배열 저장이 빠른지 확인할것

Num.push_back(i);

}//탐색할 수의 범위 지정

for (int i = 2; i < lenght; i++)

{

for (std::vector<int>::iterator it=Prime.begin(); it!=Prime.end();)

{

if (IsNotPrime(*it,i))

it = Prime.erase(it);

else

++it;

}

}//Prime 벡터에 소수만 제외하고 삭제하는 과정(에라토스테네스의 채)

for (std::vector<int>::iterator it = Prime.begin(); it != Prime.end(); it++)

{

it_value = *it;

count = 0;

for(std::vector<int>::iterator it2=Num.begin(); it2!=Num.end();)

{

if (IsDividable(*it, *it2))

*it2 = (*it2) / (*it);

count++;

}

}//소수의 갯수를 세는 과정. 모든 수를 담은 Num 벡터의 원소들중 각 소수로 나눠지는 갯수를 Count 벡터에 푸시백


std::vector<int>::iterator it = Prime.begin();

count = 0;

while (it != Prime.end())

{

ans = pow(Prime[count], Count[count]);

count++;

it++;

}//소수의 갯수와 각 소수를 제곱해서 곱하는 과정

printf("%d",ans);

}

bool IsNotPrime(int i, int j)

{

if (i%j == 0)

if (i != j)

return TRUE;

return FALSE;

}

bool IsDividable(int i, int j)

{

if (i%j == 0)

return TRUE;

else

return FALSE;

}