Skip to content

Instantly share code, notes, and snippets.

@bbagwang
Created May 22, 2019 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbagwang/5ef03bc06d33d4d75778c014e87174b2 to your computer and use it in GitHub Desktop.
Save bbagwang/5ef03bc06d33d4d75778c014e87174b2 to your computer and use it in GitHub Desktop.
FindHGT
#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