Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6.  
  7.  
  8. // 약수 찾기
  9. // 작성자 : 반재억
  10.  
  11. long findMJaeEok(long n, long m)
  12. {
  13.  
  14.  
  15.  
  16. using namespace std;
  17.  
  18.  
  19. // 찾은 데이터들
  20. vector<long> findData;
  21.  
  22. long Data = n; // 기존 숫자
  23.  
  24. long msCnt = 1; // 약수 카운트
  25.  
  26.  
  27.  
  28. // 데이터 등록
  29. while (true)
  30. {
  31.  
  32.  
  33. if (msCnt * msCnt > Data) break; // 약수는 일정 구간 이상부터 찾을 이유가 없음
  34.  
  35. if (msCnt * msCnt == Data) // 약수가 동일한 게 나오면 해당 수만 등록한다.
  36. {
  37.  
  38. findData.push_back(msCnt);
  39. break;
  40. }
  41.  
  42. if (Data % msCnt == 0) // 약수로 인정되면, 해당 수를 넣어준다.
  43. {
  44.  
  45.  
  46.  
  47. long anoMs = Data / msCnt; // 또 하나의 약수
  48.  
  49. // 두개의 약수를 넣어준다.
  50. findData.push_back(anoMs);
  51. findData.push_back(msCnt);
  52.  
  53. }
  54. msCnt++;
  55. }
  56. if (m > findData.size()) return 0; // 사이즈가 더 크면 0을 리턴
  57.  
  58. sort(findData.begin(), findData.end()); // 소트
  59.  
  60.  
  61. return findData[m - 1];
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement