OFFSET
1,1
COMMENTS
Not all Gaussian primes will be in this list as complex numbers with an odd imaginary part require a value after the radix point (".") in the quater-imaginary number system.
LINKS
Donald Knuth, An imaginary number system, Communications of the ACM 3 (4), April 1960, pp. 245-247.
OEIS Wiki, Quater-imaginary base
OEIS Wiki, Gaussian primes
Wikipedia, Quater-imaginary base
EXAMPLE
1231_(2i) = 1(2i)^3 + 2(2i)^2 + 3(2i)^1 + 1(2i)^0 = -7-2i which is a Gaussian prime.
PROG
(C++)
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <fstream>
using namespace std;
bool isPrime(int n)
{
if (n <= 1)
return false;
if (n == 2)
return true;
if (n % 2 == 0)
return false;
int rootNCeil = (int)sqrt(n) + 1;
for (int div = 3; div <= rootNCeil; div+=2)
{
if (n % div == 0)
return false;
}
return true;
}
int main()
{
const int maxDigits = 8;
unsigned int maxVal = 2 << ((maxDigits * 2) - 1);
for (unsigned int n = 0; n < maxVal; n++)
{
// Split binary representation of n into real part and imaginary part
int rp = (n & 0x00000003) - ((n & 0x00000030) >> 2) +
((n & 0x00000300) >> 4) - ((n & 0x00003000) >> 6) +
((n & 0x00030000) >> 8) - ((n & 0x00300000) >> 10) +
((n & 0x03000000) >> 12) - ((n & 0x30000000) >> 14);
int ip = ((n & 0x0000000c) >> 1) - ((n & 0x000000c0) >> 3) +
((n & 0x00000c00) >> 5) - ((n & 0x0000c000) >> 7) +
((n & 0x000c0000) >> 9) - ((n & 0x00c00000) >> 11) +
((n & 0x0c000000) >> 13) - ((n & 0xc0000000) >> 15);
if ((ip == 0 && (abs(rp) % 4 == 3) && isPrime(abs(rp))) ||
(rp == 0 && (abs(ip) % 4 == 3) && isPrime(abs(ip))) ||
(rp != 0 && ip != 0 && isPrime(rp*rp + ip*ip)) )
{
char digits[maxDigits + 1];
_itoa(n, digits, 4);
cout<<digits << ", " << rp << (ip >= 0 ? "+" : "") << ip << "i\n";
}
}
}
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Adam J.T. Partridge, Sep 22 2015
STATUS
approved