WeixiangYan/CodeTransOcean huggingface dataset:
Task: String comparison





Java: public class Compare
{
	
    
    public static void compare (String A, String B)
    {
        if (A.equals(B))
            System.debug(A + ' and  ' + B + ' are lexically equal.');
        else
            System.debug(A + ' and  ' + B + ' are not lexically equal.');

        if (A.equalsIgnoreCase(B))
            System.debug(A + ' and  ' + B + ' are case-insensitive lexically equal.');
        else
            System.debug(A + ' and  ' + B + ' are not case-insensitive lexically equal.');
 
        if (A.compareTo(B) < 0)
            System.debug(A + ' is lexically before ' + B);
        else if (A.compareTo(B) > 0)
            System.debug(A + ' is lexically after ' + B);
 
        if (A.compareTo(B) >= 0)
            System.debug(A + ' is not lexically before ' + B);
        if (A.compareTo(B) <= 0)
            System.debug(A + ' is not lexically after ' + B);
 
        System.debug('The lexical relationship is: ' + A.compareTo(B));
    }
}
Task: SOAP






PHP: <?php

$client = new SoapClient("http://example.com/soap/definition.wsdl");

$result = $client->soapFunc("hello");
$result = $client->anotherSoapFunc(34234);

$client = new SoapClient("http://example.com/soap/definition.wsdl");

print_r($client->__getTypes());

print_r($client->__getFunctions());
?>
Task: Execute HQ9+



C#: using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void RunCode(string code)
    {
        int accumulator = 0;
        var opcodes = new Dictionary<char, Action>
        {
            {'H', () => Console.WriteLine("Hello, World!"))},
            {'Q', () => Console.WriteLine(code) },
            {'9', () => Console.WriteLine(Enumerable.Range(1,100).Reverse().Select(n => string.Format("{0} bottles of beer on the wall\n{0} bottles of beer\nTake one down, pass it around\n{1} bottles of beer on the wall\n", n, n-1)).Aggregate((a,b) => a + "\n" + b))},
            {'+', () => accumulator++ }
        }

        foreach(var c in code)
            opcodes[c]();
    }
}
Task: Erdős-primes



C#: using System; using static System.Console;
class Program {
  const int lmt = (int)1e6, first = 2500; static int[] f = new int[10];
  static void Main(string[] args) {
    f[0] = 1; for (int a = 0, b = 1; b < f.Length; a = b++)
      f[b] = f[a] * (b + 1);
    int pc = 0, nth = 0, lv = 0;
    for (int i = 2; i < lmt; i++) if (is_erdos_prime(i)) {
        if (i < first) Write("{0,5:n0}{1}", i, pc++ % 5 == 4 ? "\n" : "  ");
        nth++; lv = i; }
    Write("\nCount of Erdős primes between 1 and {0:n0}: {1}\n{2} Erdős prime (the last one under {3:n0}): {4:n0}", first, pc, ord(nth), lmt, lv); }

  static string ord(int n) {
    return string.Format("{0:n0}", n) + new string[]{"th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"}[n % 10]; }

  static bool is_erdos_prime(int p) {
    if (!is_pr(p)) return false; int m = 0, t;
    while ((t = p - f[m++]) > 0) if (is_pr(t)) return false;
    return true;
    bool is_pr(int x) {
      if (x < 4) return x > 1; if ((x & 1) == 0) return false;
      for (int i = 3; i * i <= x; i += 2) if (x % i == 0) return false;
    return true; } } }
Task: Two sum



C#: using System;
using System.Collections.Generic;

public class Program
{
    public static void Main(string[] args)
    {
        int[] arr = { 0, 2, 11, 19, 90 };
        const int sum = 21;

        var ts = TwoSum(arr, sum);
        Console.WriteLine(ts != null ? $"{ts[0]}, {ts[1]}" : "no result");

        Console.ReadLine();
    }

    public static int[] TwoSum(int[] numbers, int sum)
    {
        var map = new Dictionary<int, int>();
        for (int i = 0; i < numbers.Length; i++)
        {
            
            var key = sum - numbers[i];
            if (map.ContainsKey(key))
            {
                return new[] { map[key], i };
            }
            map.Add(numbers[i], i);
        }
        return null;
    }
}
Task: Descending primes



C#: using System;

class Program {

  static bool ispr(uint n) {
    if ((n & 1) == 0 || n < 2) return n == 2;
    for (uint j = 3; j * j <= n; j += 2)
      if (n % j == 0) return false; return true; }

  static void Main(string[] args) {
    uint c = 0; int nc;
    var ps = new uint[]{ 1, 2, 3, 4, 5, 6, 7, 8, 9 };
    var nxt = new uint[128];
    while (true) {
      nc = 0;
      foreach (var a in ps) {
        if (ispr(a))
          Console.Write("{0,8}{1}", a, ++c % 5 == 0 ? "\n" : " ");
        for (uint b = a * 10, l = a % 10 + b++; b < l; b++)
          nxt[nc++] = b;
      }
      if (nc > 1) {
        Array.Resize (ref ps, nc); Array.Copy(nxt, ps, nc); }
      else break;
    }
    Console.WriteLine("\n{0} descending primes found", c);
  }
}
Task: RPG attributes generator



C#: using System;
using System.Collections.Generic;
using System.Linq;

static class Module1
{
    static Random r = new Random();

    static List<int> getThree(int n)
    {
        List<int> g3 = new List<int>();
        for (int i = 0; i < 4; i++) g3.Add(r.Next(n) + 1);
        g3.Sort(); g3.RemoveAt(0); return g3;
    }

    static List<int> getSix()
    {
        List<int> g6 = new List<int>();
        for (int i = 0; i < 6; i++) g6.Add(getThree(6).Sum());
        return g6;
    }

    static void Main(string[] args)
    {
        bool good = false; do {
            List<int> gs = getSix(); int gss = gs.Sum(); int hvc = gs.FindAll(x => x > 14).Count;
            Console.Write("attribs: {0}, sum={1}, ({2} sum, high vals={3})",
                          string.Join(", ", gs), gss, gss >= 75 ? "good" : "low", hvc);
            Console.WriteLine(" - {0}", (good = gs.Sum() >= 75 && hvc > 1) ? "success" : "failure");
        } while (!good);
    }
}
Task: Odd squarefree semiprimes



C#: using System; using static System.Console; using System.Collections;
using System.Linq; using System.Collections.Generic;

class Program { static void Main(string[] args) {
    int lmt = 1000, amt, c = 0, sr = (int)Math.Sqrt(lmt), lm2; var res = new List<int>();
    var pr = PG.Primes(lmt / 3 + 5).ToArray(); lm2 = pr.OrderBy(i => Math.Abs(sr - i)).First();
    lm2 = Array.IndexOf(pr, lm2); for (var p = 0; p < lm2; p++) { amt = 0; for (var q = p + 1; amt < lmt; q++)
      res.Add(amt = pr[p] * pr[q]); } res.Sort(); foreach(var item in res.TakeWhile(x => x < lmt))
        Write("{0,4} {1}", item, ++c % 20 == 0 ? "\n" : "");
    Write("\n\nCounted {0} odd squarefree semiprimes under {1}", c, lmt); } }

class PG { public static IEnumerable<int> Primes(int lim) {
    var flags = new bool[lim + 1]; int j = 3;
    for (int d = 8, sq = 9; sq <= lim; j += 2, sq += d += 8)
      if (!flags[j]) { yield return j;
        for (int k = sq, i = j << 1; k <= lim; k += i) flags[k] = true; }
    for (; j <= lim; j += 2) if (!flags[j]) yield return j; } }
Task: Numbers which are the cube roots of the product of their proper divisors



C#: using System;
class Program {

  static bool dc8(uint n) {
    uint res = 1, count, p, d;
    for ( ; (n & 1) == 0; n >>= 1) res++;
    for (count = 1; n % 3 == 0; n /= 3) count++;
    for (p = 5, d = 4; p * p <= n; p += d = 6 - d)
        for (res *= count, count = 1; n % p == 0; n /= p) count++;
    return n > 1 ? res * count == 4 : res * count == 8;
  }

  static void Main(string[] args) {
    Console.WriteLine("First 50 numbers which are the cube roots of the products of "
                      + "their proper divisors:");
    for (uint n = 1, count = 0, lmt = 500; count < 5e6; ++n) if (n == 1 || dc8(n))
        if (++count <= 50) Console.Write("{0,3}{1}",n, count % 10 == 0 ? '\n' : ' ');
        else if (count == lmt) Console.Write("{0,16:n0}th: {1:n0}\n", count, n, lmt *= 10);
  }
}
Task: Arithmetic numbers








VB: 


function isarit_compo(i)
     cnt=0
     sum=0
     for j=1 to sqr(i)
       if (i mod j)=0 then 
          k=i\j 
             
         if k=j then 
            cnt=cnt+1:sum=sum+j 
         else  
            cnt=cnt+2:sum=sum+j+k 
         end if
       end if
     next
   avg= sum/cnt
   isarit_compo= array((fix(avg)=avg),-(cnt>2))
end function

function rpad(a,n) rpad=right(space(n)&a,n) :end function

dim s1
sub print(s) 
  s1=s1& rpad(s,4)
  if len(s1)=40 then wscript.stdout.writeline s1:s1=""
end sub


cntr=0
cntcompo=0
i=1
wscript.stdout.writeline "the first 100 arithmetic numbers are:"
do
  a=isarit_compo(i)
  if a(0) then  
    cntcompo=cntcompo+a(1)
    cntr=cntr+1
    if cntr<=100 then print i
    if cntr=1000 then wscript.stdout.writeline vbcrlf&"1000th   : "&rpad(i,6) & " nr composites " &rpad(cntcompo,6)
    if cntr=10000 then wscript.stdout.writeline vbcrlf& "10000th  : "&rpad(i,6) & " nr composites " &rpad(cntcompo,6)
    if cntr=100000 then wscript.stdout.writeline vbcrlf &"100000th : "&rpad(i,6) & " nr composites " &rpad(cntcompo,6):exit do
  end if 
  i=i+1
loop
Task: Abbreviations, easy








VB: Private Function ValidateUserWords(userstring As String) As String
    Dim s As String
    Dim user_words() As String
    Dim command_table As Scripting.Dictionary
    Set command_table = New Scripting.Dictionary
    Dim abbreviations As Scripting.Dictionary
    Set abbreviations = New Scripting.Dictionary
    abbreviations.CompareMode = TextCompare
    Dim commandtable() As String
    Dim commands As String
    s = s & "Add ALTer  BAckup Bottom  CAppend Change SCHANGE  CInsert CLAst COMPress COpy "
    s = s & "COUnt COVerlay CURsor DELete CDelete Down DUPlicate Xedit EXPand EXTract Find "
    s = s & "NFind NFINDUp NFUp CFind FINdup FUp FOrward GET Help HEXType Input POWerinput "
    s = s & "Join SPlit SPLTJOIN  LOAD  Locate CLocate  LOWercase UPPercase  LPrefix MACRO "
    s = s & "MErge MODify MOve MSG Next Overlay PARSE PREServe PURge PUT PUTD  Query  QUIT "
    s = s & "READ  RECover REFRESH RENum REPeat  Replace CReplace  RESet  RESTore  RGTLEFT "
    s = s & "RIght LEft  SAVE  SET SHift SI  SORT  SOS  STAck STATus  TOP TRAnsfer Type Up "
    commandtable = Split(s, " ")
    Dim i As Integer
    For Each word In commandtable
        If Len(word) > 0 Then
            i = 1
            Do While Mid(word, i, 1) >= "A" And Mid(word, i, 1) <= "Z"
                i = i + 1
            Loop
            command_table.Add Key:=word, Item:=i - 1
        End If
    Next word
    For Each word In command_table
        For i = command_table(word) To Len(word)
            On Error Resume Next
            abbreviations.Add Key:=Left(word, i), Item:=UCase(word)
        Next i
    Next word
    user_words() = Split(userstring, " ")
    For Each word In user_words
        If Len(word) > 0 Then
            If abbreviations.exists(word) Then
                commands = commands & abbreviations(word) & " "
            Else
                commands = commands & "*error* "
            End If
        End If
    Next word
    ValidateUserWords = commands
End Function
Public Sub program()
    Dim guserstring As String
    guserstring = "riG   rePEAT copies  put mo   rest    types   fup.    6       poweRin"
    Debug.Print "user words:", guserstring
    Debug.Print "full words:", ValidateUserWords(guserstring)
End Sub
Task: Truncate a file








VB: Sub truncate(fpath,n)
	
	Set objfso = CreateObject("Scripting.FileSystemObject")
	If objfso.FileExists(fpath) = False Then
		WScript.Echo fpath & " does not exist"
		Exit Sub
	End If
	content = ""
	
	Set objinstream = CreateObject("Adodb.Stream")
	With objinstream
		.Type = 1
		.Open
		.LoadFromFile(fpath)
		
		If n <= .Size Then
			content = .Read(n)
		Else
			WScript.Echo "The specified size is larger than the file content"
			Exit Sub
		End If
		.Close
	End With
	
	Set objoutstream = CreateObject("Adodb.Stream")
	With objoutstream
		.Type = 1
		.Open
		.Write content
		.SaveToFile fpath,2
		.Close
	End With
	Set objinstream = Nothing
	Set objoutstream = Nothing
	Set objfso = Nothing
End Sub


Call truncate("C:\temp\test.txt",30)
Task: Exceptions








VB: Sub foo1()
    err.raise(vbObjectError + 1050)
End Sub

Sub foo2()
    Error vbObjectError + 1051
End Sub
Task: Pseudo-random numbers_PCG32





Java: public class PCG32 {
    private static final long N = 6364136223846793005L;

    private long state = 0x853c49e6748fea9bL;
    private long inc = 0xda3e39cb94b95bdbL;

    public void seed(long seedState, long seedSequence) {
        state = 0;
        inc = (seedSequence << 1) | 1;
        nextInt();
        state = state + seedState;
        nextInt();
    }

    public int nextInt() {
        long old = state;
        state = old * N + inc;
        int shifted = (int) (((old >>> 18) ^ old) >>> 27);
        int rot = (int) (old >>> 59);
        return (shifted >>> rot) | (shifted << ((~rot + 1) & 31));
    }

    public double nextFloat() {
        var u = Integer.toUnsignedLong(nextInt());
        return (double) u / (1L << 32);
    }

    public static void main(String[] args) {
        var r = new PCG32();

        r.seed(42, 54);
        System.out.println(Integer.toUnsignedString(r.nextInt()));
        System.out.println(Integer.toUnsignedString(r.nextInt()));
        System.out.println(Integer.toUnsignedString(r.nextInt()));
        System.out.println(Integer.toUnsignedString(r.nextInt()));
        System.out.println(Integer.toUnsignedString(r.nextInt()));
        System.out.println();

        int[] counts = {0, 0, 0, 0, 0};
        r.seed(987654321, 1);
        for (int i = 0; i < 100_000; i++) {
            int j = (int) Math.floor(r.nextFloat() * 5.0);
            counts[j]++;
        }

        System.out.println("The counts for 100,000 repetitions are:");
        for (int i = 0; i < counts.length; i++) {
            System.out.printf("  %d : %d\n", i, counts[i]);
        }
    }
}
Task: Pseudo-random numbers_Combined recursive generator MRG32k3a





Java: public class App {
    private static long mod(long x, long y) {
        long m = x % y;
        if (m < 0) {
            if (y < 0) {
                return m - y;
            } else {
                return m + y;
            }
        }
        return m;
    }

    public static class RNG {
        
        private final long[] a1 = {0, 1403580, -810728};
        private static final long m1 = (1L << 32) - 209;
        private long[] x1;
        
        private final long[] a2 = {527612, 0, -1370589};
        private static final long m2 = (1L << 32) - 22853;
        private long[] x2;
        
        private static final long d = m1 + 1;

        public void seed(long state) {
            x1 = new long[]{state, 0, 0};
            x2 = new long[]{state, 0, 0};
        }

        public long nextInt() {
            long x1i = mod(a1[0] * x1[0] + a1[1] * x1[1] + a1[2] * x1[2], m1);
            long x2i = mod(a2[0] * x2[0] + a2[1] * x2[1] + a2[2] * x2[2], m2);
            long z = mod(x1i - x2i, m1);

            
            x1 = new long[]{x1i, x1[0], x1[1]};
            
            x2 = new long[]{x2i, x2[0], x2[1]};

            return z + 1;
        }

        public double nextFloat() {
            return 1.0 * nextInt() / d;
        }
    }

    public static void main(String[] args) {
        RNG rng = new RNG();

        rng.seed(1234567);
        System.out.println(rng.nextInt());
        System.out.println(rng.nextInt());
        System.out.println(rng.nextInt());
        System.out.println(rng.nextInt());
        System.out.println(rng.nextInt());
        System.out.println();

        int[] counts = {0, 0, 0, 0, 0};
        rng.seed(987654321);
        for (int i = 0; i < 100_000; i++) {
            int value = (int) Math.floor(rng.nextFloat() * 5.0);
            counts[value]++;
        }
        for (int i = 0; i < counts.length; i++) {
            System.out.printf("%d: %d%n", i, counts[i]);
        }
    }
}
Task: Rodrigues’ rotation formula





Java: 

class Vector{
  private double x, y, z;

  public Vector(double x1,double y1,double z1){
    x = x1;
    y = y1;
    z = z1;
  }
  
  void printVector(int x,int y){
    text("( " + this.x + " )  \u00ee + ( " + this.y + " ) + \u0135 ( " + this.z + ") \u006b\u0302",x,y);
  }

  public double norm() {
    return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
  }
  
  public Vector normalize(){
    double length = this.norm();
    return new Vector(this.x / length, this.y / length, this.z / length);
  }
  
  public double dotProduct(Vector v2) {
    return this.x*v2.x + this.y*v2.y + this.z*v2.z;
  }
  
  public Vector crossProduct(Vector v2) {
    return new Vector(this.y*v2.z - this.z*v2.y, this.z*v2.x - this.x*v2.z, this.x*v2.y - this.y*v2.x);
  }
  
  public double getAngle(Vector v2) {
    return Math.acos(this.dotProduct(v2) / (this.norm()*v2.norm()));
  }
  
  public Vector aRotate(Vector v, double a) {
    double ca = Math.cos(a), sa = Math.sin(a);
    double t = 1.0 - ca;
    double x = v.x, y = v.y, z = v.z;
    Vector[] r = {
        new Vector(ca + x*x*t, x*y*t - z*sa, x*z*t + y*sa),
        new Vector(x*y*t + z*sa, ca + y*y*t, y*z*t - x*sa),
        new Vector(z*x*t - y*sa, z*y*t + x*sa, ca + z*z*t)
    };
    return new Vector(this.dotProduct(r[0]), this.dotProduct(r[1]), this.dotProduct(r[2]));
  }
}

void setup(){
  Vector v1 = new Vector(5d, -6d, 4d),v2 = new Vector(8d, 5d, -30d);
  double a = v1.getAngle(v2);
  Vector cp = v1.crossProduct(v2);
  Vector normCP = cp.normalize();
  Vector np = v1.aRotate(normCP,a);
  
  size(1200,600);
  fill(#000000);
  textSize(30);
  
  text("v1 = ",10,100);
  v1.printVector(60,100);
  text("v2 = ",10,150);
  v2.printVector(60,150);
  text("rV = ",10,200);
  np.printVector(60,200);
}
Task: Wilson primes of order n

C: #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <gmp.h>

bool *sieve(int limit) {
    int i, p;
    limit++;
    
    bool *c = calloc(limit, sizeof(bool)); 
    c[0] = true;
    c[1] = true;
    for (i = 4; i < limit; i += 2) c[i] = true;
    p = 3; 
    while (true) {
        int p2 = p * p;
        if (p2 >= limit) break;
        for (i = p2; i < limit; i += 2 * p) c[i] = true;
        while (true) {
            p += 2;
            if (!c[p]) break;
        }
    }
    return c;
}

int main() {
    const int limit = 11000;
    int i, j, n, pc = 0;
    unsigned long p;
    bool *c = sieve(limit);
    for (i = 0; i < limit; ++i) {
        if (!c[i]) ++pc;
    }
    unsigned long *primes = (unsigned long *)malloc(pc * sizeof(unsigned long));
    for (i = 0, j = 0; i < limit; ++i) {
        if (!c[i]) primes[j++] = i;
    }
    mpz_t *facts = (mpz_t *)malloc(limit *sizeof(mpz_t));
    for (i = 0; i < limit; ++i) mpz_init(facts[i]);
    mpz_set_ui(facts[0], 1);
    for (i = 1; i < limit; ++i) mpz_mul_ui(facts[i], facts[i-1], i);
    mpz_t f, sign;
    mpz_init(f);
    mpz_init_set_ui(sign, 1);
    printf(" n:  Wilson primes\n");
    printf("--------------------\n");
    for (n = 1; n < 12; ++n) {
        printf("%2d:  ", n);
        mpz_neg(sign, sign);
        for (i = 0; i < pc; ++i) {
            p = primes[i];
            if (p < n) continue;
            mpz_mul(f, facts[n-1], facts[p-n]);
            mpz_sub(f, f, sign);
            if (mpz_divisible_ui_p(f, p*p)) printf("%ld ", p);
        }
        printf("\n");
    }
    free(c);
    free(primes);
    for (i = 0; i < limit; ++i) mpz_clear(facts[i]);
    free(facts);
    return 0;
}
Task: Concatenate two primes is also prime

C: #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <locale.h>

bool isPrime(int n) {
    if (n < 2) return false;
    if (n%2 == 0) return n == 2;
    if (n%3 == 0) return n == 3;
    int d = 5;
    while (d*d <= n) {
        if (n%d == 0) return false;
        d += 2;
        if (n%d == 0) return false;
        d += 4;
    }
    return true;
}

int compare(const void* a, const void* b) {
    int arg1 = *(const int*)a;
    int arg2 = *(const int*)b;
    if (arg1 < arg2) return -1;
    if (arg1 > arg2) return 1;
    return 0;
}

int main() {
    int primes[30] = {2}, results[200];
    int i, j, p, q, pq, limit = 100, pc = 1, rc = 0;
    for (i = 3; i < limit; i += 2) {
        if (isPrime(i)) primes[pc++] = i;
    }
    for (i = 0; i < pc; ++i) {
        p = primes[i];
        for (j = 0; j < pc; ++j) {
            q = primes[j];
            pq = (q < 10) ? p * 10 + q : p * 100 + q;
            if (isPrime(pq)) results[rc++] = pq;
        }
    }
    qsort(results, rc, sizeof(int), compare);
    setlocale(LC_NUMERIC, "");
    printf("Two primes under 100 concatenated together to form another prime:\n");
    for (i = 0, j = 0; i < rc; ++i) {
        if (i > 0 && results[i] == results[i-1]) continue;
        printf("%'6d ", results[i]);
        if (++j % 10 == 0) printf("\n");
    }
    printf("\n\nFound %d such concatenated primes.\n", j);
    return 0;
}
Task: Next special primes

C: #include <stdio.h>
#include <stdbool.h>

bool isPrime(int n) {
    int d;
    if (n < 2)  return false;
    if (!(n%2)) return n == 2;
    if (!(n%3)) return n == 3;
    d = 5;
    while (d*d <= n) {
        if (!(n%d)) return false;
        d += 2;
        if (!(n%d)) return false;
        d += 4;
    }
    return true;
}

int main() {
    int i, lastSpecial = 3, lastGap = 1;
    printf("Special primes under 1,050:\n");
    printf("Prime1 Prime2 Gap\n");
    printf("%6d %6d %3d\n", 2, 3, lastGap);
    for (i = 5; i < 1050; i += 2) {
        if (isPrime(i) && (i-lastSpecial) > lastGap) {
            lastGap = i - lastSpecial;
            printf("%6d %6d %3d\n", lastSpecial, i, lastGap);
            lastSpecial = i;
        }
    }
}
Task: Cubic special primes

C: #include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <locale.h>

bool *sieve(int limit) {
    int i, p;
    limit++;
    
    bool *c = calloc(limit, sizeof(bool)); 
    c[0] = true;
    c[1] = true;
    for (i = 4; i < limit; i += 2) c[i] = true;
    p = 3; 
    while (true) {
        int p2 = p * p;
        if (p2 >= limit) break;
        for (i = p2; i < limit; i += 2 * p) c[i] = true;
        while (true) {
            p += 2;
            if (!c[p]) break;
        }
    }
    return c;
}

bool isCube(int n) {
    int s = (int)cbrt((double)n);
    return s*s*s == n;
}

int main() {
    const int limit = 14999;
    int i, j, p, pc = 0, gap = 1, count = 1, lastCubicSpecial = 3;
    const char *fmt = "%'7d %'7d %'6d %'4d\n";
    bool *c = sieve(limit);
    for (i = 0; i < limit; ++i) {
        if (!c[i]) ++pc;
    }
    int *primes = (int *)malloc(pc * sizeof(int));
    for (i = 0, j = 0; i < limit; ++i) {
        if (!c[i]) primes[j++] = i;
    }
    free(c);
    printf("Cubic special primes under 15,000:\n");
    printf(" Prime1  Prime2    Gap  Cbrt\n");
    setlocale(LC_NUMERIC, "");
    printf(fmt, 2, 3, 1, 1);
    for (i = 2; i < pc; ++i) {
        p = primes[i];
        gap = p - lastCubicSpecial;
        if (isCube(gap)) {
            printf(fmt, lastCubicSpecial, p, gap, (int)cbrt((double)gap));
            lastCubicSpecial = p;
            ++count;
        }
    }
    printf("\n%d such primes found.\n", count+1);
    free(primes);
    return 0;
}
Task: Primes whose first and last number is 3

C: #include<stdio.h>
#include<stdlib.h>
#include<math.h>

int isprime( int p ) {
    int i;
    if(p==2) return 1;
    if(!(p%2)) return 0;
    for(i=3; i*i<=p; i+=2) {
       if(!(p%i)) return 0;
    }
    return 1;
}

int main(void) {
    int np = 1, d, i, n;
    printf( "3  " );
    for(d=1; d<6; d++) {
        for(i=3; i<pow(10,d)-1; i+=10) {
            n = i + 3*pow(10,d);
            if(isprime(n)) {
                ++np;
                if(n<4009) {
                    printf("%d  ",n);
                    if(!(np%10)) printf("\n");
                }
            }
        }
    }
    printf( "\n\nThere were %d primes of the form 3x3 below one million.\n", np );
    return 0;
}