Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- #include <vector>
- #include <algorithm>
- // 약수 찾기
- // 작성자 : 반재억
- long findMJaeEok(long n, long m)
- {
- using namespace std;
- // 찾은 데이터들
- vector<long> findData;
- long Data = n; // 기존 숫자
- long msCnt = 1; // 약수 카운트
- // 데이터 등록
- while (true)
- {
- if (msCnt * msCnt > Data) break; // 약수는 일정 구간 이상부터 찾을 이유가 없음
- if (msCnt * msCnt == Data) // 약수가 동일한 게 나오면 해당 수만 등록한다.
- {
- findData.push_back(msCnt);
- break;
- }
- if (Data % msCnt == 0) // 약수로 인정되면, 해당 수를 넣어준다.
- {
- long anoMs = Data / msCnt; // 또 하나의 약수
- // 두개의 약수를 넣어준다.
- findData.push_back(anoMs);
- findData.push_back(msCnt);
- }
- msCnt++;
- }
- if (m > findData.size()) return 0; // 사이즈가 더 크면 0을 리턴
- sort(findData.begin(), findData.end()); // 소트
- return findData[m - 1];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement