WeixiangYan/CodeTransOcean huggingface dataset:
Task: Almost prime

C: #include <stdio.h>

int kprime(int n, int k)
{
	int p, f = 0;
	for (p = 2; f < k && p*p <= n; p++)
		while (0 == n % p)
			n /= p, f++;

	return f + (n > 1) == k;
}

int main(void)
{
	int i, c, k;

	for (k = 1; k <= 5; k++) {
		printf("k = %d:", k);

		for (i = 2, c = 0; c < 10; i++)
			if (kprime(i, k)) {
				printf(" %d", i);
				c++;
			}

		putchar('\n');
	}

	return 0;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ALMOST-PRIME.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 CONTROL-VARS.
          03 K              PIC 9.
          03 I              PIC 999.
          03 SEEN           PIC 99.
          03 N              PIC 999.
          03 P              PIC 99.
          03 P-SQUARED      PIC 9(4).
          03 F              PIC 99.
          03 N-DIV-P        PIC 999V999.
          03 FILLER         REDEFINES N-DIV-P.
             05 NEXT-N      PIC 999.
             05 FILLER      PIC 999.
                88 N-DIVS-P VALUE ZERO.
          
       01 OUT-VARS.
          03 K-LN           PIC X(70).
          03 K-LN-PTR       PIC 99.
          03 LN-HDR.
             05 FILLER      PIC X(4) VALUE "K = ".
             05 K-OUT       PIC 9.
             05 FILLER      PIC X VALUE ":".
          03 I-FMT.
             05 FILLER      PIC X VALUE SPACE.
             05 I-OUT       PIC ZZ9.
       
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM K-ALMOST-PRIMES VARYING K FROM 1 BY 1
               UNTIL K IS GREATER THAN 5.
           STOP RUN.
           
       K-ALMOST-PRIMES.
           MOVE SPACES TO K-LN.
           MOVE 1 TO K-LN-PTR.
           MOVE ZERO TO SEEN.
           MOVE K TO K-OUT.
           STRING LN-HDR DELIMITED BY SIZE INTO K-LN 
               WITH POINTER K-LN-PTR.
           PERFORM I-K-ALMOST-PRIME VARYING I FROM 2 BY 1
               UNTIL SEEN IS EQUAL TO 10.
           DISPLAY K-LN.
       
       I-K-ALMOST-PRIME.
           MOVE ZERO TO F, P-SQUARED.
           MOVE I TO N.
           PERFORM PRIME-FACTOR VARYING P FROM 2 BY 1
               UNTIL F IS NOT LESS THAN K 
               OR P-SQUARED IS GREATER THAN N. 
           IF N IS GREATER THAN 1, ADD 1 TO F.
           IF F IS EQUAL TO K,
               MOVE I TO I-OUT,
               ADD 1 TO SEEN,
               STRING I-FMT DELIMITED BY SIZE INTO K-LN
                   WITH POINTER K-LN-PTR.
       
       PRIME-FACTOR.
           MULTIPLY P BY P GIVING P-SQUARED.
           DIVIDE N BY P GIVING N-DIV-P.
           PERFORM DIVIDE-FACTOR UNTIL NOT N-DIVS-P.
           
       DIVIDE-FACTOR.
           MOVE NEXT-N TO N.
           ADD 1 TO F.
           DIVIDE N BY P GIVING N-DIV-P.
Task: Almost prime


C++: #include <cstdlib>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <list>

bool k_prime(unsigned n, unsigned k) {
    unsigned f = 0;
    for (unsigned p = 2; f < k && p * p <= n; p++)
        while (0 == n % p) { n /= p; f++; }
    return f + (n > 1 ? 1 : 0) == k;
}

std::list<unsigned> primes(unsigned k, unsigned n)  {
    std::list<unsigned> list;
    for (unsigned i = 2;list.size() < n;i++)
        if (k_prime(i, k)) list.push_back(i);
    return list;
}

int main(const int argc, const char* argv[]) {
    using namespace std;
    for (unsigned k = 1; k <= 5; k++) {
        ostringstream os("");
        const list<unsigned> l = primes(k, 10);
        for (list<unsigned>::const_iterator i = l.begin(); i != l.end(); i++)
            os << setw(4) << *i;
        cout << "k = " << k << ':' << os.str() << endl;
    }

	return EXIT_SUCCESS;
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ALMOST-PRIME.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 CONTROL-VARS.
          03 K              PIC 9.
          03 I              PIC 999.
          03 SEEN           PIC 99.
          03 N              PIC 999.
          03 P              PIC 99.
          03 P-SQUARED      PIC 9(4).
          03 F              PIC 99.
          03 N-DIV-P        PIC 999V999.
          03 FILLER         REDEFINES N-DIV-P.
             05 NEXT-N      PIC 999.
             05 FILLER      PIC 999.
                88 N-DIVS-P VALUE ZERO.
          
       01 OUT-VARS.
          03 K-LN           PIC X(70).
          03 K-LN-PTR       PIC 99.
          03 LN-HDR.
             05 FILLER      PIC X(4) VALUE "K = ".
             05 K-OUT       PIC 9.
             05 FILLER      PIC X VALUE ":".
          03 I-FMT.
             05 FILLER      PIC X VALUE SPACE.
             05 I-OUT       PIC ZZ9.
       
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM K-ALMOST-PRIMES VARYING K FROM 1 BY 1
               UNTIL K IS GREATER THAN 5.
           STOP RUN.
           
       K-ALMOST-PRIMES.
           MOVE SPACES TO K-LN.
           MOVE 1 TO K-LN-PTR.
           MOVE ZERO TO SEEN.
           MOVE K TO K-OUT.
           STRING LN-HDR DELIMITED BY SIZE INTO K-LN 
               WITH POINTER K-LN-PTR.
           PERFORM I-K-ALMOST-PRIME VARYING I FROM 2 BY 1
               UNTIL SEEN IS EQUAL TO 10.
           DISPLAY K-LN.
       
       I-K-ALMOST-PRIME.
           MOVE ZERO TO F, P-SQUARED.
           MOVE I TO N.
           PERFORM PRIME-FACTOR VARYING P FROM 2 BY 1
               UNTIL F IS NOT LESS THAN K 
               OR P-SQUARED IS GREATER THAN N. 
           IF N IS GREATER THAN 1, ADD 1 TO F.
           IF F IS EQUAL TO K,
               MOVE I TO I-OUT,
               ADD 1 TO SEEN,
               STRING I-FMT DELIMITED BY SIZE INTO K-LN
                   WITH POINTER K-LN-PTR.
       
       PRIME-FACTOR.
           MULTIPLY P BY P GIVING P-SQUARED.
           DIVIDE N BY P GIVING N-DIV-P.
           PERFORM DIVIDE-FACTOR UNTIL NOT N-DIVS-P.
           
       DIVIDE-FACTOR.
           MOVE NEXT-N TO N.
           ADD 1 TO F.
           DIVIDE N BY P GIVING N-DIV-P.
Task: Almost prime





Java: public class AlmostPrime {
    public static void main(String[] args) {
        for (int k = 1; k <= 5; k++) {
            System.out.print("k = " + k + ":");

            for (int i = 2, c = 0; c < 10; i++) {
                if (kprime(i, k)) {
                    System.out.print(" " + i);
                    c++;
                }
            }

            System.out.println("");
        }
    }

    public static boolean kprime(int n, int k) {
        int f = 0;
        for (int p = 2; f < k && p * p <= n; p++) {
            while (n % p == 0) {
                n /= p;
                f++;
            }
        }
        return f + ((n > 1) ? 1 : 0) == k;
    }
}





COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ALMOST-PRIME.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 CONTROL-VARS.
          03 K              PIC 9.
          03 I              PIC 999.
          03 SEEN           PIC 99.
          03 N              PIC 999.
          03 P              PIC 99.
          03 P-SQUARED      PIC 9(4).
          03 F              PIC 99.
          03 N-DIV-P        PIC 999V999.
          03 FILLER         REDEFINES N-DIV-P.
             05 NEXT-N      PIC 999.
             05 FILLER      PIC 999.
                88 N-DIVS-P VALUE ZERO.
          
       01 OUT-VARS.
          03 K-LN           PIC X(70).
          03 K-LN-PTR       PIC 99.
          03 LN-HDR.
             05 FILLER      PIC X(4) VALUE "K = ".
             05 K-OUT       PIC 9.
             05 FILLER      PIC X VALUE ":".
          03 I-FMT.
             05 FILLER      PIC X VALUE SPACE.
             05 I-OUT       PIC ZZ9.
       
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM K-ALMOST-PRIMES VARYING K FROM 1 BY 1
               UNTIL K IS GREATER THAN 5.
           STOP RUN.
           
       K-ALMOST-PRIMES.
           MOVE SPACES TO K-LN.
           MOVE 1 TO K-LN-PTR.
           MOVE ZERO TO SEEN.
           MOVE K TO K-OUT.
           STRING LN-HDR DELIMITED BY SIZE INTO K-LN 
               WITH POINTER K-LN-PTR.
           PERFORM I-K-ALMOST-PRIME VARYING I FROM 2 BY 1
               UNTIL SEEN IS EQUAL TO 10.
           DISPLAY K-LN.
       
       I-K-ALMOST-PRIME.
           MOVE ZERO TO F, P-SQUARED.
           MOVE I TO N.
           PERFORM PRIME-FACTOR VARYING P FROM 2 BY 1
               UNTIL F IS NOT LESS THAN K 
               OR P-SQUARED IS GREATER THAN N. 
           IF N IS GREATER THAN 1, ADD 1 TO F.
           IF F IS EQUAL TO K,
               MOVE I TO I-OUT,
               ADD 1 TO SEEN,
               STRING I-FMT DELIMITED BY SIZE INTO K-LN
                   WITH POINTER K-LN-PTR.
       
       PRIME-FACTOR.
           MULTIPLY P BY P GIVING P-SQUARED.
           DIVIDE N BY P GIVING N-DIV-P.
           PERFORM DIVIDE-FACTOR UNTIL NOT N-DIVS-P.
           
       DIVIDE-FACTOR.
           MOVE NEXT-N TO N.
           ADD 1 TO F.
           DIVIDE N BY P GIVING N-DIV-P.
Task: Almost prime







Python: from prime_decomposition import decompose
from itertools import islice, count
try: 
    from functools import reduce
except: 
    pass


def almostprime(n, k=2):
    d = decompose(n)
    try:
        terms = [next(d) for i in range(k)]
        return reduce(int.__mul__, terms, 1) == n
    except:
        return False

if __name__ == '__main__':
    for k in range(1,6):
        print('%i: %r' % (k, list(islice((n for n in count() if almostprime(n, k)), 10))))



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ALMOST-PRIME.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 CONTROL-VARS.
          03 K              PIC 9.
          03 I              PIC 999.
          03 SEEN           PIC 99.
          03 N              PIC 999.
          03 P              PIC 99.
          03 P-SQUARED      PIC 9(4).
          03 F              PIC 99.
          03 N-DIV-P        PIC 999V999.
          03 FILLER         REDEFINES N-DIV-P.
             05 NEXT-N      PIC 999.
             05 FILLER      PIC 999.
                88 N-DIVS-P VALUE ZERO.
          
       01 OUT-VARS.
          03 K-LN           PIC X(70).
          03 K-LN-PTR       PIC 99.
          03 LN-HDR.
             05 FILLER      PIC X(4) VALUE "K = ".
             05 K-OUT       PIC 9.
             05 FILLER      PIC X VALUE ":".
          03 I-FMT.
             05 FILLER      PIC X VALUE SPACE.
             05 I-OUT       PIC ZZ9.
       
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM K-ALMOST-PRIMES VARYING K FROM 1 BY 1
               UNTIL K IS GREATER THAN 5.
           STOP RUN.
           
       K-ALMOST-PRIMES.
           MOVE SPACES TO K-LN.
           MOVE 1 TO K-LN-PTR.
           MOVE ZERO TO SEEN.
           MOVE K TO K-OUT.
           STRING LN-HDR DELIMITED BY SIZE INTO K-LN 
               WITH POINTER K-LN-PTR.
           PERFORM I-K-ALMOST-PRIME VARYING I FROM 2 BY 1
               UNTIL SEEN IS EQUAL TO 10.
           DISPLAY K-LN.
       
       I-K-ALMOST-PRIME.
           MOVE ZERO TO F, P-SQUARED.
           MOVE I TO N.
           PERFORM PRIME-FACTOR VARYING P FROM 2 BY 1
               UNTIL F IS NOT LESS THAN K 
               OR P-SQUARED IS GREATER THAN N. 
           IF N IS GREATER THAN 1, ADD 1 TO F.
           IF F IS EQUAL TO K,
               MOVE I TO I-OUT,
               ADD 1 TO SEEN,
               STRING I-FMT DELIMITED BY SIZE INTO K-LN
                   WITH POINTER K-LN-PTR.
       
       PRIME-FACTOR.
           MULTIPLY P BY P GIVING P-SQUARED.
           DIVIDE N BY P GIVING N-DIV-P.
           PERFORM DIVIDE-FACTOR UNTIL NOT N-DIVS-P.
           
       DIVIDE-FACTOR.
           MOVE NEXT-N TO N.
           ADD 1 TO F.
           DIVIDE N BY P GIVING N-DIV-P.
Task: Almost prime








VB: for k = 1 to 5
    print "k = "; k; " :";
    i = 2
    c = 0
    while c < 10
        if kPrime(i, k) then
            print " "; using("###", i);
            c = c +1
        end if
        i = i +1
    wend
    print
next k
end

function kPrime(n, k)
    f = 0
    for i = 2 to n
        while n mod i = 0
            if f = k then kPrime = 0
            f = f +1
            n = int(n / i)
        wend
    next i
    kPrime = abs(f = k)
end function


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ALMOST-PRIME.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 CONTROL-VARS.
          03 K              PIC 9.
          03 I              PIC 999.
          03 SEEN           PIC 99.
          03 N              PIC 999.
          03 P              PIC 99.
          03 P-SQUARED      PIC 9(4).
          03 F              PIC 99.
          03 N-DIV-P        PIC 999V999.
          03 FILLER         REDEFINES N-DIV-P.
             05 NEXT-N      PIC 999.
             05 FILLER      PIC 999.
                88 N-DIVS-P VALUE ZERO.
          
       01 OUT-VARS.
          03 K-LN           PIC X(70).
          03 K-LN-PTR       PIC 99.
          03 LN-HDR.
             05 FILLER      PIC X(4) VALUE "K = ".
             05 K-OUT       PIC 9.
             05 FILLER      PIC X VALUE ":".
          03 I-FMT.
             05 FILLER      PIC X VALUE SPACE.
             05 I-OUT       PIC ZZ9.
       
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM K-ALMOST-PRIMES VARYING K FROM 1 BY 1
               UNTIL K IS GREATER THAN 5.
           STOP RUN.
           
       K-ALMOST-PRIMES.
           MOVE SPACES TO K-LN.
           MOVE 1 TO K-LN-PTR.
           MOVE ZERO TO SEEN.
           MOVE K TO K-OUT.
           STRING LN-HDR DELIMITED BY SIZE INTO K-LN 
               WITH POINTER K-LN-PTR.
           PERFORM I-K-ALMOST-PRIME VARYING I FROM 2 BY 1
               UNTIL SEEN IS EQUAL TO 10.
           DISPLAY K-LN.
       
       I-K-ALMOST-PRIME.
           MOVE ZERO TO F, P-SQUARED.
           MOVE I TO N.
           PERFORM PRIME-FACTOR VARYING P FROM 2 BY 1
               UNTIL F IS NOT LESS THAN K 
               OR P-SQUARED IS GREATER THAN N. 
           IF N IS GREATER THAN 1, ADD 1 TO F.
           IF F IS EQUAL TO K,
               MOVE I TO I-OUT,
               ADD 1 TO SEEN,
               STRING I-FMT DELIMITED BY SIZE INTO K-LN
                   WITH POINTER K-LN-PTR.
       
       PRIME-FACTOR.
           MULTIPLY P BY P GIVING P-SQUARED.
           DIVIDE N BY P GIVING N-DIV-P.
           PERFORM DIVIDE-FACTOR UNTIL NOT N-DIVS-P.
           
       DIVIDE-FACTOR.
           MOVE NEXT-N TO N.
           ADD 1 TO F.
           DIVIDE N BY P GIVING N-DIV-P.
Task: Almost prime




Go: package main

import "fmt"

func kPrime(n, k int) bool {
    nf := 0
    for i := 2; i <= n; i++ {
        for n%i == 0 {
            if nf == k {
                return false
            }
            nf++
            n /= i
        }
    }
    return nf == k
}

func gen(k, n int) []int {
    r := make([]int, n)
    n = 2
    for i := range r {
        for !kPrime(n, k) {
            n++
        }
        r[i] = n
        n++
    }
    return r
}

func main() {
    for k := 1; k <= 5; k++ {
        fmt.Println(k, gen(k, 10))
    }
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ALMOST-PRIME.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 CONTROL-VARS.
          03 K              PIC 9.
          03 I              PIC 999.
          03 SEEN           PIC 99.
          03 N              PIC 999.
          03 P              PIC 99.
          03 P-SQUARED      PIC 9(4).
          03 F              PIC 99.
          03 N-DIV-P        PIC 999V999.
          03 FILLER         REDEFINES N-DIV-P.
             05 NEXT-N      PIC 999.
             05 FILLER      PIC 999.
                88 N-DIVS-P VALUE ZERO.
          
       01 OUT-VARS.
          03 K-LN           PIC X(70).
          03 K-LN-PTR       PIC 99.
          03 LN-HDR.
             05 FILLER      PIC X(4) VALUE "K = ".
             05 K-OUT       PIC 9.
             05 FILLER      PIC X VALUE ":".
          03 I-FMT.
             05 FILLER      PIC X VALUE SPACE.
             05 I-OUT       PIC ZZ9.
       
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM K-ALMOST-PRIMES VARYING K FROM 1 BY 1
               UNTIL K IS GREATER THAN 5.
           STOP RUN.
           
       K-ALMOST-PRIMES.
           MOVE SPACES TO K-LN.
           MOVE 1 TO K-LN-PTR.
           MOVE ZERO TO SEEN.
           MOVE K TO K-OUT.
           STRING LN-HDR DELIMITED BY SIZE INTO K-LN 
               WITH POINTER K-LN-PTR.
           PERFORM I-K-ALMOST-PRIME VARYING I FROM 2 BY 1
               UNTIL SEEN IS EQUAL TO 10.
           DISPLAY K-LN.
       
       I-K-ALMOST-PRIME.
           MOVE ZERO TO F, P-SQUARED.
           MOVE I TO N.
           PERFORM PRIME-FACTOR VARYING P FROM 2 BY 1
               UNTIL F IS NOT LESS THAN K 
               OR P-SQUARED IS GREATER THAN N. 
           IF N IS GREATER THAN 1, ADD 1 TO F.
           IF F IS EQUAL TO K,
               MOVE I TO I-OUT,
               ADD 1 TO SEEN,
               STRING I-FMT DELIMITED BY SIZE INTO K-LN
                   WITH POINTER K-LN-PTR.
       
       PRIME-FACTOR.
           MULTIPLY P BY P GIVING P-SQUARED.
           DIVIDE N BY P GIVING N-DIV-P.
           PERFORM DIVIDE-FACTOR UNTIL NOT N-DIVS-P.
           
       DIVIDE-FACTOR.
           MOVE NEXT-N TO N.
           ADD 1 TO F.
           DIVIDE N BY P GIVING N-DIV-P.
Task: Almost prime






PHP: <?php


function isKPrime($n, $k)
{
    $f = 0;
    for ($j = 2; $j <= $n; $j++) {
        while ($n % $j == 0) {
            if ($f == $k)
                return false;
            $f++;
            $n = floor($n / $j);
        } // while
    } // for $j
    return ($f == $k);
}

for ($k = 1; $k <= 5; $k++) {
    echo "k = ", $k, ":";
    $i = 2;
    $c = 0;
    while ($c < 10) {
        if (isKPrime($i, $k)) {
            echo " ", str_pad($i, 3, ' ', STR_PAD_LEFT);
            $c++;
        } 
        $i++;
    }
    echo PHP_EOL;
}
?>
Task: Almost prime






PHP: <?php


function isKPrime($n, $k)
{
    $f = 0;
    for ($j = 2; $j <= $n; $j++) {
        while ($n % $j == 0) {
            if ($f == $k)
                return false;
            $f++;
            $n = floor($n / $j);
        } // while
    } // for $j
    return ($f == $k);
}

for ($k = 1; $k <= 5; $k++) {
    echo "k = ", $k, ":";
    $i = 2;
    $c = 0;
    while ($c < 10) {
        if (isKPrime($i, $k)) {
            echo " ", str_pad($i, 3, ' ', STR_PAD_LEFT);
            $c++;
        } 
        $i++;
    }
    echo PHP_EOL;
}
?>






Ada: with Prime_Numbers, Ada.Text_IO; 
 
procedure Test_Kth_Prime is
   
   package Integer_Numbers is new 
     Prime_Numbers (Natural, 0, 1, 2); 
   use Integer_Numbers;
   
   Out_Length: constant Positive := 10; 
   N: Positive; 
   
begin
   for K in 1 .. 5 loop
      Ada.Text_IO.Put("K =" & Integer'Image(K) &":  ");
      N := 2;
      for I in 1 .. Out_Length loop
	 while Decompose(N)'Length /= K loop
	    N := N + 1;
	 end loop; 
	 Ada.Text_IO.Put(Integer'Image(Integer(N)));
	 N := N + 1;
      end loop;
      Ada.Text_IO.New_Line;
   end loop;
end Test_Kth_Prime;
Task: Almost prime






PHP: <?php


function isKPrime($n, $k)
{
    $f = 0;
    for ($j = 2; $j <= $n; $j++) {
        while ($n % $j == 0) {
            if ($f == $k)
                return false;
            $f++;
            $n = floor($n / $j);
        } // while
    } // for $j
    return ($f == $k);
}

for ($k = 1; $k <= 5; $k++) {
    echo "k = ", $k, ":";
    $i = 2;
    $c = 0;
    while ($c < 10) {
        if (isKPrime($i, $k)) {
            echo " ", str_pad($i, 3, ' ', STR_PAD_LEFT);
            $c++;
        } 
        $i++;
    }
    echo PHP_EOL;
}
?>




COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ALMOST-PRIME.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 CONTROL-VARS.
          03 K              PIC 9.
          03 I              PIC 999.
          03 SEEN           PIC 99.
          03 N              PIC 999.
          03 P              PIC 99.
          03 P-SQUARED      PIC 9(4).
          03 F              PIC 99.
          03 N-DIV-P        PIC 999V999.
          03 FILLER         REDEFINES N-DIV-P.
             05 NEXT-N      PIC 999.
             05 FILLER      PIC 999.
                88 N-DIVS-P VALUE ZERO.
          
       01 OUT-VARS.
          03 K-LN           PIC X(70).
          03 K-LN-PTR       PIC 99.
          03 LN-HDR.
             05 FILLER      PIC X(4) VALUE "K = ".
             05 K-OUT       PIC 9.
             05 FILLER      PIC X VALUE ":".
          03 I-FMT.
             05 FILLER      PIC X VALUE SPACE.
             05 I-OUT       PIC ZZ9.
       
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM K-ALMOST-PRIMES VARYING K FROM 1 BY 1
               UNTIL K IS GREATER THAN 5.
           STOP RUN.
           
       K-ALMOST-PRIMES.
           MOVE SPACES TO K-LN.
           MOVE 1 TO K-LN-PTR.
           MOVE ZERO TO SEEN.
           MOVE K TO K-OUT.
           STRING LN-HDR DELIMITED BY SIZE INTO K-LN 
               WITH POINTER K-LN-PTR.
           PERFORM I-K-ALMOST-PRIME VARYING I FROM 2 BY 1
               UNTIL SEEN IS EQUAL TO 10.
           DISPLAY K-LN.
       
       I-K-ALMOST-PRIME.
           MOVE ZERO TO F, P-SQUARED.
           MOVE I TO N.
           PERFORM PRIME-FACTOR VARYING P FROM 2 BY 1
               UNTIL F IS NOT LESS THAN K 
               OR P-SQUARED IS GREATER THAN N. 
           IF N IS GREATER THAN 1, ADD 1 TO F.
           IF F IS EQUAL TO K,
               MOVE I TO I-OUT,
               ADD 1 TO SEEN,
               STRING I-FMT DELIMITED BY SIZE INTO K-LN
                   WITH POINTER K-LN-PTR.
       
       PRIME-FACTOR.
           MULTIPLY P BY P GIVING P-SQUARED.
           DIVIDE N BY P GIVING N-DIV-P.
           PERFORM DIVIDE-FACTOR UNTIL NOT N-DIVS-P.
           
       DIVIDE-FACTOR.
           MOVE NEXT-N TO N.
           ADD 1 TO F.
           DIVIDE N BY P GIVING N-DIV-P.
Task: Almost prime








VB: Private Function kprime(ByVal n As Integer, k As Integer) As Boolean
    Dim p As Integer, factors As Integer
    p = 2
    factors = 0
    Do While factors < k And p * p <= n
        Do While n Mod p = 0
            n = n / p
            factors = factors + 1
        Loop
        p = p + 1
    Loop
    factors = factors - (n > 1) 
    kprime = factors = k
End Function
 
Private Sub almost_primeC()
    Dim nextkprime As Integer, count As Integer
    Dim k As Integer
    For k = 1 To 5
        Debug.Print "k ="; k; ":";
        nextkprime = 2
        count = 0
        Do While count < 10
            If kprime(nextkprime, k) Then
                Debug.Print " "; Format(CStr(nextkprime), "@@@@@");
                count = count + 1
            End If
            nextkprime = nextkprime + 1
        Loop
        Debug.Print
    Next k
End Sub
Task: Integer comparison



C#: using System;

class Program
{
    static void Main()
    {
        int a = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());
        if (a < b)
            Console.WriteLine("{0} is less than {1}", a, b);
        if (a == b)
            Console.WriteLine("{0} equals {1}", a, b);
        if (a > b)
            Console.WriteLine("{0} is greater than {1}", a, b);
    }
}









Ada: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;

procedure Compare_Ints is
   A, B : Integer;
begin
   Get(Item => A);
   Get(Item => B);

   
   if A = B then
      Put_Line("A equals B");
   end if;

   
   if A < B then
      Put_Line("A is less than B");
   end if;

   
   if A > B then
      Put_Line("A is greater than B");
   end if;
end Compare_Ints;
Task: Integer comparison

C: #include <stdio.h>

int main()
{
  int a, b;
  scanf("%d %d", &a, &b);

  if (a < b)
    printf("%d is less than %d\n", a, b);

  if (a == b)
    printf("%d is equal to %d\n", a, b);

  if (a > b)
    printf("%d is greater than %d\n", a, b);

  return 0;
}











Ada: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_Io;

procedure Compare_Ints is
   A, B : Integer;
begin
   Get(Item => A);
   Get(Item => B);

   
   if A = B then
      Put_Line("A equals B");
   end if;

   
   if A < B then
      Put_Line("A is less than B");
   end if;

   
   if A > B then
      Put_Line("A is greater than B");
   end if;
end Compare_Ints;