We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
private static int[] quads = new int[498].AsEnumerable().Select((n, i) => 4 * (i + 1) * (i + 1)).ToArray();
private static int GCD(int a, int b)
{
return a == 0 ? b : GCD(b % a, a);
}
private static bool contains(int div)
{
int left = 0, right = 497;
do
{
if (quads[left] == div || quads[right] == div) return true;
int mid = (left + right) / 2;
if (quads[mid] < div) left = mid;
else right = mid;
}
while (left < right - 1);
return quads[left] == div || quads[right] == div;
}
private static int getDivs(int n, out int evn)
{
int cnt = 1;
evn = 0;
for (int i = 2; i <= (int)Math.Sqrt(n); i++)
{
if (n % i == 0)
{
cnt += n / i == i ? 1 : 2;
if(contains(i)) evn++;
if(n / i != i && contains(n/i)) evn++;
}
}
return cnt;
}
public static string solveEvenQuadDiv(int n)
{
if (n < 8 || n % 4 != 0) return "0";
int tot = getDivs(n, out int evn);
int gcd = GCD(evn, tot);
return $"{evn/gcd}/{tot/gcd}";
}
Mehta and his Laziness
You are viewing a single comment's thread. Return to all comments →
C# - I wouldn't name it hard...
...though some guess is required