Created
October 4, 2018 04:18
-
-
Save Indp-Dustin/0915cb3a7f769aaac102e44d63bc0de2 to your computer and use it in GitHub Desktop.
FindM
This file contains hidden or 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
long findM3(long n, long m) | |
{ | |
int c = 0; | |
long v = 1; | |
bool squared = false; | |
int va[1000]; | |
while (v * v <= n) | |
{ | |
if (v * v < n) | |
{ | |
if (!(n % v)) | |
{ | |
va[c] = v; | |
if (m == ++c) | |
{ | |
return v; | |
} | |
} | |
} | |
else | |
{ | |
squared = true; | |
va[c] = v; | |
if (m == ++c) | |
{ | |
return v; | |
} | |
break; | |
} | |
v++; | |
} | |
if (squared && (m % 2)) | |
{ | |
return n / va[m - c]; | |
} | |
else if (!squared && !(m % 2) && (m <= c * 2)) | |
{ | |
return n / va[c - (m - c)]; | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment