##C, 186 183 bytes
#include<stddef.h>
size_t a,b,c,d,m,x;size_t F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}
The primality test is very inefficient, so the computation will struggle a bit for n > 16
and become painfully long for n = 19
. Nevertheless it works and gives the expected results.
The code assumes that size_t
is a 64bit type, which is true for both 64bit Linux and Windows.
Bonus: unfortunately we are required to use 64bit types, which lead to an overhead of 36 bytes. The following version works for n <= 15
using int
and is 150 byte long:
a,b,c,d,m,x;F(n){a=0,b=1;while(n){x=b;b+=a;a=x;c=0,m=1;while(x)d=x%16,m*=d<10?c+=m*d,10:1,x/=16;d=c>1;x=2;while(x<c)if(c%x++==0)d=0;d&&--n;}return a;}
Test main:
#include <stdio.h>
int main() {
printf("Input - Output\n");
for (int i = 1; i < 20; ++i) {
printf("%2d - %ld\n", i, F(i));
}
}