Created
May 22, 2019 07:41
-
-
Save bbagwang/5ef03bc06d33d4d75778c014e87174b2 to your computer and use it in GitHub Desktop.
FindHGT
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; | |
long findHGT(long n, long m) | |
{ | |
long count = 1; | |
bool doOnce=false; | |
for(long i=1;i<=n/2;++i) | |
{ | |
if (n % i == 0) | |
{ | |
count++; | |
if (i * i == n&&!doOnce) | |
{ | |
/*count++;*/ | |
doOnce = true; | |
} | |
} | |
if (count == m+1) | |
{ | |
return i; | |
} | |
} | |
} | |
int main() | |
{ | |
long n; | |
long m; | |
cin >> n >> m; | |
cout<< findHGT(n, m); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment