WeixiangYan/CodeTransOcean huggingface dataset:
Task: Digit fifth powers


C++: #include <iostream>
#include <cmath>
#include <chrono>

using namespace std;
using namespace chrono;

int main() {
  auto st = high_resolution_clock::now();
  const uint i5 = 100000, i4 = 10000, i3 = 1000, i2 = 100, i1 = 10;
  uint p4[] = { 0, 1, 32, 243 }, nums[10], p5[10], t = 0, 
    m5, m4, m3, m2, m1, m0; m5 = m4 = m3 = m2 = m1 = m0 = 0;
  for (uint i = 0; i < 10; i++) p5[i] = pow(nums[i] = i, 5);
  for (auto i : p4) { auto im =      m5, ip =      i; m4 = 0;
  for (auto j : p5) { auto jm = im + m4, jp = ip + j; m3 = 0;
  for (auto k : p5) { auto km = jm + m3, kp = jp + k; m2 = 0;
  for (auto l : p5) { auto lm = km + m2, lp = kp + l; m1 = 0;
  for (auto m : p5) { auto mm = lm + m1, mp = lp + m; m0 = 0;
  for (auto n : p5) { auto nm = mm + m0++;
    if (nm == mp + n && nm > 1) t += nm;
  } m1 += i1; } m2 += i2; } m3 += i3; } m4 += i4; } m5 += i5; }
  auto et = high_resolution_clock::now();
  std::cout << t << " " <<
    duration_cast<nanoseconds>(et - st).count() / 1000.0 << " μs";
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. DIGIT-FIFTH-POWER.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 CANDIDATE          PIC 9(6).
          03 MAXIMUM            PIC 9(6).
          03 DIGITS             PIC 9 OCCURS 6 TIMES,
                                REDEFINES CANDIDATE.
          03 DIGIT              PIC 9.
          03 POWER-SUM          PIC 9(6).
          03 TOTAL              PIC 9(6).

       01 OUT-FORMAT.
          03 OUT-NUM            PIC Z(5)9.

       PROCEDURE DIVISION.
       BEGIN.
           MOVE ZERO TO TOTAL.
           COMPUTE MAXIMUM = 9 ** 5 * 6.
           PERFORM TEST-NUMBER
               VARYING CANDIDATE FROM 2 BY 1
               UNTIL CANDIDATE IS GREATER THAN MAXIMUM.
           DISPLAY '------ +'.
           DISPLAY TOTAL.
           STOP RUN.

       TEST-NUMBER.
           MOVE ZERO TO POWER-SUM.
           PERFORM ADD-DIGIT-POWER
               VARYING DIGIT FROM 1 BY 1
               UNTIL DIGIT IS GREATER THAN 6.
           IF POWER-SUM IS EQUAL TO CANDIDATE,
               MOVE CANDIDATE TO OUT-NUM,
               DISPLAY OUT-NUM,
               ADD CANDIDATE TO TOTAL.
       
       ADD-DIGIT-POWER.
           COMPUTE POWER-SUM = POWER-SUM + DIGITS(DIGIT) ** 5.
Task: Find words which contains more than 3 e vowels


C++: #include <iostream>
#include <fstream>

bool test(const std::string &line) {
    unsigned int e = 0;
    for (char c : line) {
        switch(std::tolower(c)) {
            case 'a': return false;
            case 'i': return false;
            case 'o': return false;
            case 'u': return false;
            case 'e': ++e;
        }
    }
    return e > 3;
}

int main() {
    std::ifstream dict{"unixdict.txt"};
    
    if (! dict.is_open()) {
        std::cerr << "Cannot open unixdict.txt\n";
        return 3;
    }
    
    for (std::string line; std::getline(dict, line);) {
        if (test(line)) std::cout << line << std::endl;
    }
    
    return 0;
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. E-WORDS.
       
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT DICT ASSIGN TO DISK
           ORGANIZATION LINE SEQUENTIAL.
           
       DATA DIVISION.
       FILE SECTION.
       FD DICT 
           LABEL RECORD STANDARD
           VALUE OF FILE-ID IS "unixdict.txt".
       01 WORD            PIC X(64).
       
       WORKING-STORAGE SECTION.
       01 E               PIC 99.
       01 OTHER           PIC 99.
       
       PROCEDURE DIVISION.
       BEGIN.
           OPEN INPUT DICT.
           
       READ-WORD.
           READ DICT, AT END CLOSE DICT, STOP RUN.
           PERFORM CHECK-WORD.
           GO TO READ-WORD.
           
       CHECK-WORD.
           MOVE ZERO TO E, OTHER.
           INSPECT WORD TALLYING OTHER FOR ALL 'a'.
           INSPECT WORD TALLYING E FOR ALL 'e'.
           INSPECT WORD TALLYING OTHER FOR ALL 'i'.
           INSPECT WORD TALLYING OTHER FOR ALL 'o'.
           INSPECT WORD TALLYING OTHER FOR ALL 'u'.
           IF E IS GREATER THAN 3 AND OTHER IS EQUAL TO ZERO,
               DISPLAY WORD.
Task: Hello world_Newbie


C++: #include <iostream>
int main() {
    using namespace std;
    cout << "Hello, World!" << endl;
    return 0;
}








COBOL: program-id. hello-world.

procedure division.
  display "Hello, World!"

  goback
  .
Task: Base 16 numbers needing a to f


C++: #include <iomanip>
#include <iostream>



bool nondecimal(unsigned int n) {
    for (; n > 0; n >>= 4) {
        if ((n & 0xF) > 9)
            return true;
    }
    return false;
}

int main() {
    unsigned int count = 0;
    for (unsigned int n = 0; n < 501; ++n) {
        if (nondecimal(n)) {
            ++count;
            std::cout << std::setw(3) << n << (count % 15 == 0 ? '\n' : ' ');
        }
    }
    std::cout << "\n\n" << count << " such numbers found.\n";
}








COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. BASE-16.
        
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 VARIABLES        COMP.
           02 STRP          PIC 99 VALUE 1.
           02 N             PIC 999.
           02 NTEMP         PIC 999.
           02 N16           PIC 999.
           02 NMOD16        PIC 99.
           02 BASE16-FLAG   PIC 9.
              88 BASE16     VALUE 1.
           02 AMOUNT        PIC 999 VALUE 0.
           
        01 OUTPUT-FORMAT.
           02 LINESTR       PIC X(72).
           02 OUTN          PIC BZZ9.
           
        PROCEDURE DIVISION.
        BEGIN.
            PERFORM NONDEC VARYING N FROM 1 BY 1 
                UNTIL N IS GREATER THAN 500.
            PERFORM DISPLAY-LINE.
            DISPLAY ' '.
            MOVE AMOUNT TO OUTN.
            DISPLAY OUTN ' numbers found.'
            STOP RUN.
        
        NONDEC.
            MOVE N TO NTEMP.
            PERFORM IS-NONDEC.
            IF BASE16
                MOVE N TO OUTN
                STRING OUTN DELIMITED BY SIZE INTO LINESTR
                    WITH POINTER STRP
                ADD 1 TO AMOUNT
                IF STRP IS EQUAL TO 73 PERFORM DISPLAY-LINE.
                        
        DISPLAY-LINE.
            IF STRP IS NOT EQUAL TO 1 DISPLAY LINESTR.
            MOVE 1 TO STRP.
            MOVE ' ' TO LINESTR.
            
        IS-NONDEC.
            IF NTEMP IS EQUAL TO ZERO
                MOVE 0 TO BASE16-FLAG
            ELSE
                DIVIDE NTEMP BY 16 GIVING N16
                COMPUTE NMOD16 = NTEMP - N16 * 16
                IF NMOD16 IS NOT LESS THAN 10
                    MOVE 1 TO BASE16-FLAG
                ELSE
                    MOVE N16 TO NTEMP
                    GO TO IS-NONDEC.
Task: Address of a variable


C++: int i;
void* address_of_i = &i;








COBOL: data division.
working-storage section.
01 ptr usage pointer.
01 var pic x(64).

procedure division.
set ptr to address of var.
Task: Fixed length records


C++: #include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>

void reverse(std::istream& in, std::ostream& out) {
    constexpr size_t record_length = 80;
    char record[record_length];
    while (in.read(record, record_length)) {
        std::reverse(std::begin(record), std::end(record));
        out.write(record, record_length);
    }
    out.flush();
}

int main(int argc, char** argv) {
    std::ifstream in("infile.dat", std::ios_base::binary);
    if (!in) {
        std::cerr << "Cannot open input file\n";
        return EXIT_FAILURE;
    }
    std::ofstream out("outfile.dat", std::ios_base::binary);
    if (!out) {
        std::cerr << "Cannot open output file\n";
        return EXIT_FAILURE;
    }
    try {
        in.exceptions(std::ios_base::badbit);
        out.exceptions(std::ios_base::badbit);
        reverse(in, out);
    } catch (const std::exception& ex) {
        std::cerr << "I/O error: " << ex.what() << '\n';
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}








COBOL:       
      
      
       identification division.
       program-id. lrecl80.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       input-output section.
       file-control.
           select infile
               assign to infile-name
               organization is sequential
               file status is infile-status
           .
           select outfile
               assign to outfile-name
               organization is sequential
               file status is outfile-status
           .

       data division.
       file section.
       fd infile.
           01 input-text pic x(80).

       fd outfile.
           01 output-text pic x(80).

       working-storage section.
       01 infile-name.
          05 value "infile.dat".
       01 infile-status pic xx.
          88 ok-input value '00'.
          88 eof-input value '10'.

       01 outfile-name.
          05 value "outfile.dat".
       01 outfile-status pic xx.
          88 ok-output value '00'.

       procedure division.

       open input infile
       if not ok-input then
           display "error opening input " infile-name upon syserr
           goback
       end-if

       open output outfile
       if not ok-output
           display "error opening output " outfile-name upon syserr
           goback
       end-if

      
       read infile
       perform until not ok-input
           move function reverse(input-text) to output-text

           write output-text
           if not ok-output then
               display "error writing: " output-text upon syserr
           end-if
           read infile
       end-perform

       close infile outfile

      
       open input outfile
       if not ok-output then
           display "error opening input " outfile-name upon syserr
           goback
       end-if

       read outfile
       perform until not ok-output
           display function trim(output-text trailing)
           read outfile
       end-perform

       close outfile

       goback.
       end program lrecl80.
Task: Find words which contains all the vowels


C++: #include <bitset>
#include <cctype>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>

bool contains_all_vowels_once(const std::string& word) {
    std::bitset<5> vowels;
    for (char ch : word) {
        ch = std::tolower(static_cast<unsigned char>(ch));
        size_t bit = 0;
        switch (ch) {
        case 'a': bit = 0; break;
        case 'e': bit = 1; break;
        case 'i': bit = 2; break;
        case 'o': bit = 3; break;
        case 'u': bit = 4; break;
        default: continue;
        }
        if (vowels.test(bit))
            return false;
        vowels.set(bit);
    }
    return vowels.all();
}

int main(int argc, char** argv) {
    const char* filename(argc < 2 ? "unixdict.txt" : argv[1]);
    std::ifstream in(filename);
    if (!in) {
        std::cerr << "Cannot open file '" << filename << "'.\n";
        return EXIT_FAILURE;
    }
    std::string word;
    int n = 0;
    while (getline(in, word)) {
        if (word.size() > 10 && contains_all_vowels_once(word))
            std::cout << std::setw(2) << ++n << ": " << word << '\n';
    }
    return EXIT_SUCCESS;
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ALL-VOWELS.
       
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT DICT ASSIGN TO DISK
           ORGANIZATION LINE SEQUENTIAL.
           
       DATA DIVISION.
       FILE SECTION.
       FD DICT 
           LABEL RECORD STANDARD
           VALUE OF FILE-ID IS "unixdict.txt".
       01 WORD            PIC X(64).
       
       WORKING-STORAGE SECTION.
       01 A               PIC 99.
       01 E               PIC 99.
       01 I               PIC 99.
       01 O               PIC 99.
       01 U               PIC 99.
       01 LEN             PIC 99.
       
       PROCEDURE DIVISION.
       BEGIN.
           OPEN INPUT DICT.
           
       READ-WORD.
           READ DICT, AT END CLOSE DICT, STOP RUN.
           PERFORM CHECK-WORD.
           GO TO READ-WORD.
           
       CHECK-WORD.
           MOVE ZERO TO LEN, A, E, I, O, U.
           INSPECT WORD TALLYING LEN FOR CHARACTERS 
               BEFORE INITIAL SPACE.
           INSPECT WORD TALLYING A FOR ALL 'a'.
           INSPECT WORD TALLYING E FOR ALL 'e'.
           INSPECT WORD TALLYING I FOR ALL 'i'.
           INSPECT WORD TALLYING O FOR ALL 'o'.
           INSPECT WORD TALLYING U FOR ALL 'u'.
           IF LEN IS GREATER THAN 10
              AND 1 IS EQUAL TO A AND E AND I AND O AND U,
               DISPLAY WORD.
Task: Loops_Infinite


C++: while (true)
  std::cout << "SPAM\n";








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Spam.

       PROCEDURE DIVISION.
           PERFORM UNTIL 1 <> 1
               DISPLAY "SPAM"
           END-PERFORM

           GOBACK
           .
Task: Function definition


C++: inline double multiply(double a, double b)
{
   return a*b;
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. myTest.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  x   PIC 9(3) VALUE 3.
       01  y   PIC 9(3) VALUE 2.
       01  z   PIC 9(9).
       PROCEDURE DIVISION.
           CALL "myMultiply" USING 
               BY CONTENT x, BY CONTENT y, 
               BY REFERENCE z.
           DISPLAY z.
           STOP RUN.
       END PROGRAM myTest.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. myMultiply.
       DATA DIVISION.
       LINKAGE SECTION.
       01  x   PIC 9(3).
       01  y   PIC 9(3).
       01  z   PIC 9(9).
       PROCEDURE DIVISION USING x, y, z.
           MULTIPLY x BY y GIVING z.
           EXIT PROGRAM.
       END PROGRAM myMultiply.
Task: Sum of the digits of n is substring of n


C++: #include <iostream>

int digitSum(int n) {
    int s = 0;
    do {s += n % 10;} while (n /= 10);
    return s;
}

int main() {
    for (int i=0; i<1000; i++) {
        auto s_i = std::to_string(i);
        auto s_ds = std::to_string(digitSum(i));
        if (s_i.find(s_ds) != std::string::npos) {
            std::cout << i << " ";
        }
    }
    std::cout << std::endl;
    return 0;
}








COBOL:         IDENTIFICATION DIVISION.
        PROGRAM-ID. SUM-SUBSTRING.
            
        DATA DIVISION.
        WORKING-STORAGE SECTION.
        01 CALCULATION.
           02 N         PIC 9999.
           02 X         PIC 9.
           02 DSUM      PIC 99.
           02 N-DIGITS  REDEFINES N.
              03 ND     PIC 9 OCCURS 4 TIMES.
           02 S-DIGITS  REDEFINES DSUM.
              03 SUMD   PIC 9 OCCURS 2 TIMES.
        01 OUTPUT-FORMAT.
           02 N-OUT     PIC ZZZ9.
        
        PROCEDURE DIVISION.
        BEGIN.
            PERFORM TESTNUMBER VARYING N FROM 0 BY 1
                    UNTIL N IS EQUAL TO 1000.
            STOP RUN.
        
        TESTNUMBER SECTION.
        BEGIN.
            PERFORM SUM-DIGITS.
            SET X TO 1.
            IF DSUM IS LESS THAN 10 GO TO ONE-DIGIT-CHECK.
        
        TWO-DIGIT-CHECK.
            IF X IS GREATER THAN 3 GO TO DONE.
            IF ND(X) = SUMD(1) AND ND(X + 1) = SUMD(2) GO TO SHOW.
            ADD 1 TO X.
            GO TO TWO-DIGIT-CHECK.
            
        ONE-DIGIT-CHECK.
            IF X IS GREATER THAN 4 GO TO DONE.
            IF ND(X) = SUMD(2) GO TO SHOW.
            ADD 1 TO X.
            GO TO ONE-DIGIT-CHECK.
        
        SHOW.
            MOVE N TO N-OUT.
            DISPLAY N-OUT.
        DONE. EXIT.
        
        SUM-DIGITS SECTION.
        BEGIN.
            SET DSUM TO 0.
            SET X TO 1.
        LOOP.    
            ADD ND(X) TO DSUM.
            ADD 1 TO X.
            IF X IS LESS THAN 5 GO TO LOOP.
Task: Create a file on magnetic tape


C++: #include <iostream>
#include <fstream>

#if defined(_WIN32) || defined(WIN32)
constexpr auto FILENAME = "tape.file";
#else
constexpr auto FILENAME = "/dev/tape";
#endif

int main() {
    std::filebuf fb;
    fb.open(FILENAME,std::ios::out);
    std::ostream os(&fb);
    os << "Hello World\n";
    fb.close();
    return 0;
}








COBOL:        >>SOURCE FORMAT IS FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. MAKE-TAPE-FILE.

ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
    SELECT TAPE-FILE
        ASSIGN "./TAPE.FILE"
        ORGANIZATION IS LINE SEQUENTIAL.

DATA DIVISION.
FILE SECTION.
FD TAPE-FILE.
01 TAPE-FILE-RECORD PIC X(51).

PROCEDURE DIVISION.
    OPEN OUTPUT SHARING WITH ALL OTHER TAPE-FILE
    WRITE TAPE-FILE-RECORD 
        FROM "COBOL treats tape files and text files identically."
    END-WRITE
    STOP RUN.
Task: Execute HQ9+


C++: void runCode(string code)
{
    int c_len = code.length();
    unsigned accumulator=0;
    int bottles;
    for(int i=0;i<c_len;i++)
    {
        switch(code[i])
        {
            case 'Q':
                cout << code << endl;
                break;

            case 'H':
                cout << "Hello, world!" << endl;
                break;

            case '9':
                
                bottles = 99;
                do {
                    cout << bottles << " bottles of beer on the wall" << endl;
                    cout << bottles << " bottles of beer" << endl;
                    cout << "Take one down, pass it around" << endl;
                    cout << --bottles << " bottles of beer on the wall" << endl << endl;
                } while( bottles > 0 );
                break;

            case '+':
                
                accumulator++;
                break;
        }
    }
};








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Exec-Hq9.

       DATA DIVISION.
       LOCAL-STORAGE SECTION.
       78  Code-Length VALUE 256.

       01  i           PIC 999.
       01  accumulator PIC 999.

       01  bottles     PIC 999.

       LINKAGE SECTION.
       01  hq9-code    PIC X(Code-Length).
       
       PROCEDURE DIVISION USING BY VALUE hq9-code.
           PERFORM VARYING i FROM 1 BY 1 UNTIL Code-Length < i
               EVALUATE hq9-code (i:1)
                   WHEN "Q"
                       DISPLAY FUNCTION TRIM(hq9-code)

                   WHEN "H"
                       DISPLAY "Hello, World!"

                   WHEN "9"
                       MOVE 99 TO bottles
                       PERFORM UNTIL bottles = ZERO
                           DISPLAY
                               bottles " bottles of beer on the wall"
                           DISPLAY bottles " bottles of beer"
                           DISPLAY "Take one down, pass it around"
                           SUBTRACT 1 FROM bottles
                           DISPLAY
                               bottles " bottles of beer on the wall"
                           DISPLAY SPACE
                       END-PERFORM

                   WHEN "+"
                       ADD 1 TO accumulator
               END-EVALUATE
           END-PERFORM

           GOBACK
           .
Task: Tau function


C++: #include <iomanip>
#include <iostream>


unsigned int divisor_count(unsigned int n) {
    unsigned int total = 1;
    
    for (; (n & 1) == 0; n >>= 1)
        ++total;
    
    for (unsigned int p = 3; p * p <= n; p += 2) {
        unsigned int count = 1;
        for (; n % p == 0; n /= p)
            ++count;
        total *= count;
    }
    
    if (n > 1)
        total *= 2;
    return total;
}

int main() {
    const unsigned int limit = 100;
    std::cout << "Count of divisors for the first " << limit << " positive integers:\n";
    for (unsigned int n = 1; n <= limit; ++n) {
        std::cout << std::setw(3) << divisor_count(n);
        if (n % 20 == 0)
            std::cout << '\n';
    }
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. TAU-FUNCTION.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 TAU-VARS.
          03 TOTAL              PIC 999.
          03 N                  PIC 999.
          03 FILLER             REDEFINES N.
             05 FILLER          PIC 99.
             05 FILLER          PIC 9.
                88 N-EVEN       VALUES 0, 2, 4, 6, 8.
          03 P                  PIC 999.
          03 P-SQUARED          PIC 999.
          03 N-DIV-P            PIC 999V999.
          03 FILLER             REDEFINES N-DIV-P.
             05 NEXT-N          PIC 999.
             05 FILLER          PIC 999.
                88 DIVISIBLE    VALUE ZERO.
          03 F-COUNT            PIC 999.
       01 CONTROL-VARS.
          03 I                  PIC 999.
       01 OUT-VARS.
          03 OUT-ITM            PIC ZZ9.
          03 OUT-STR            PIC X(80) VALUE SPACES.
          03 OUT-PTR            PIC 99 VALUE 1.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM SHOW-TAU VARYING I FROM 1 BY 1
               UNTIL I IS GREATER THAN 100.
           STOP RUN.
       
       SHOW-TAU.
           MOVE I TO N.
           PERFORM TAU.
           MOVE TOTAL TO OUT-ITM.
           STRING OUT-ITM DELIMITED BY SIZE INTO OUT-STR
               WITH POINTER OUT-PTR.
           IF OUT-PTR IS EQUAL TO 61,
               DISPLAY OUT-STR,
               MOVE 1 TO OUT-PTR.

       TAU.
           MOVE 1 TO TOTAL.
           PERFORM POWER-OF-2 UNTIL NOT N-EVEN.
           MOVE ZERO TO P-SQUARED.
           PERFORM ODD-FACTOR THRU ODD-FACTOR-LOOP
               VARYING P FROM 3 BY 2
               UNTIL P-SQUARED IS GREATER THAN N.
           IF N IS GREATER THAN 1,
               MULTIPLY 2 BY TOTAL.
       POWER-OF-2.
           ADD 1 TO TOTAL.
           DIVIDE 2 INTO N.
       ODD-FACTOR.
           MULTIPLY P BY P GIVING P-SQUARED.
           MOVE 1 TO F-COUNT.
       ODD-FACTOR-LOOP.
           DIVIDE N BY P GIVING N-DIV-P.
           IF DIVISIBLE,
               MOVE NEXT-N TO N,
               ADD 1 TO F-COUNT,
               GO TO ODD-FACTOR-LOOP.
           MULTIPLY F-COUNT BY TOTAL.
Task: Product of divisors


C++: #include <cmath>
#include <iomanip>
#include <iostream>


unsigned int divisor_count(unsigned int n) {
    unsigned int total = 1;
    
    for (; (n & 1) == 0; n >>= 1)
        ++total;
    
    for (unsigned int p = 3; p * p <= n; p += 2) {
        unsigned int count = 1;
        for (; n % p == 0; n /= p)
            ++count;
        total *= count;
    }
    
    if (n > 1)
        total *= 2;
    return total;
}


unsigned int divisor_product(unsigned int n) {
    return static_cast<unsigned int>(std::pow(n, divisor_count(n)/2.0));
}

int main() {
    const unsigned int limit = 50;
    std::cout << "Product of divisors for the first " << limit << " positive integers:\n";
    for (unsigned int n = 1; n <= limit; ++n) {
        std::cout << std::setw(11) << divisor_product(n);
        if (n % 5 == 0)
            std::cout << '\n';
    }
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID.  PRODUCT-OF-DIVISORS.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 VARIABLES.
          03 DIVISOR-PRODUCTS    PIC 9(9) OCCURS 50 TIMES.
          03 NUM                 PIC 999.
          03 MUL                 PIC 999.
      
       01 OUTPUT-FORMAT.
          03 NUM-OUT             PIC Z(9)9.
          03 LINE-PTR            PIC 99 VALUE 1.
          03 OUT-LINE            PIC X(50) VALUE SPACES.

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM INIT VARYING NUM FROM 1 BY 1
               UNTIL NUM IS GREATER THAN 50.
           PERFORM CALCULATE-MULTIPLES VARYING MUL FROM 1 BY 1
               UNTIL MUL IS GREATER THAN 50.
           PERFORM OUTPUT-NUM VARYING NUM FROM 1 BY 1
               UNTIL NUM IS GREATER THAN 50.
           STOP RUN.

       INIT.
           MOVE 1 TO DIVISOR-PRODUCTS(NUM).
       
       CALCULATE-MULTIPLES.
           PERFORM MULTIPLY-NUM VARYING NUM FROM MUL BY MUL
               UNTIL NUM IS GREATER THAN 50.
 
       MULTIPLY-NUM.
           MULTIPLY MUL BY DIVISOR-PRODUCTS(NUM).

       OUTPUT-NUM.
           MOVE DIVISOR-PRODUCTS(NUM) TO NUM-OUT.
           STRING NUM-OUT DELIMITED BY SIZE INTO OUT-LINE
               WITH POINTER LINE-PTR.
           IF LINE-PTR IS EQUAL TO 51,
               DISPLAY OUT-LINE,
               MOVE SPACES TO OUT-LINE,
               MOVE 1 TO LINE-PTR.