Primality Test Refactoring I devised a new primality test isPrimeNumber() below which determines if 1000000007 is prime.
It works fine but the code looks unprofessional in my opinion. Is there any way to refactor it to make it more readable? Maybe inline the recursive gcd() function so everything is self-contained in the isPrimeNumber() function etc.,...? Any tips? Thanks!
// Primality Test
// Every n is prime if all lattice points on x+y=n are visible from the origin.

#include &lt;stdio.h&gt;
#include &lt;stdint.h&gt;
#include &lt;math.h&gt;

#define NOT_PRIME_NUMBER 0
#define PRIME_NUMBER 1


uint64_t gcd(uint64_t a, uint64_t b)
{
    return (b != 0) ? gcd(b, a % b) : a;
}


int isPrimeNumber(uint64_t n)
{
    if (n == 2 || n == 3 || n == 5)
    {
        return PRIME_NUMBER;
    }
    
    uint64_t m = n % 10;

    if (m == 1 || m == 3 || m == 7 || m == 9)
    {
        uint64_t x, y;
        uint64_t step = 0, maxStep = sqrt(n) / 2;

        // Start near line x=y.
        x = (n / 2) + 2;
        y = n - x;

        do {

            // Check lattice point visibility...
            if (gcd(x, y) != 1)
            {
                return NOT_PRIME_NUMBER;
            }

            x++; y--; step++;

        } while (step &lt; maxStep);
    }
    else
    {
        return NOT_PRIME_NUMBER;
    }

    return PRIME_NUMBER;
}


int main(int argc, char* argv)
{
    uint64_t n = 1000000007;

    if (isPrimeNumber(n) == PRIME_NUMBER)
    {
        printf(&quot;%llu prime.&quot;, n);
    }
    else
    {
        printf(&quot;%llu not prime.&quot;, n);
    }

    return 0;
}
Your m digit checking can be simplified and your do while loop can be replaced with the simpler for loop. The constants also seem excessive given that non-zero truthiness is baked into C.
int isPrimeNumber(uint64_t n)
{
    if (n==2 || n==3) return 1;
    if (n%2==0) return 0;
    
    // Start near line x=y.
    uint64_t x = (n / 2) + 2;
    uint64_t y = n - x;

    uint64_t count = sqrt(n) / 2;
    for (uint64_t i=0;i&lt;count;++i) {
        // Check lattice point visibility...
        if (gcd(x, y) != 1) return 0;

        x++; y--;
    }

    return 1;
}