WeixiangYan/CodeTransOcean huggingface dataset:
Task: Old Russian measure of length


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

using namespace std;


class ormConverter
{
public:
    ormConverter() :  AR( 0.7112f ), CE( 0.01f ), DI( 0.0254f ), FU( 0.3048f ), KI( 1000.0f ), LI( 0.00254f ), ME( 1.0f ),
		      MI( 7467.6f ), PI( 0.1778f ), SA( 2.1336f ), TO( 0.000254f ), VE( 0.04445f ), VR( 1066.8f ) {}
    void convert( char c, float l )
    {
	system( "cls" );
	cout << endl << l;
	switch( c )
	{
	    case 'A': cout << " Arshin to:";     l *= AR; break;
	    case 'C': cout << " Centimeter to:"; l *= CE; break;
	    case 'D': cout << " Diuym to:";      l *= DI; break;
	    case 'F': cout << " Fut to:";        l *= FU; break;
	    case 'K': cout << " Kilometer to:";  l *= KI; break;
	    case 'L': cout << " Liniya to:";     l *= LI; break;
	    case 'M': cout << " Meter to:";      l *= ME; break;
	    case 'I': cout << " Milia to:";      l *= MI; break;
	    case 'P': cout << " Piad to:";       l *= PI; break;
	    case 'S': cout << " Sazhen to:";     l *= SA; break;
	    case 'T': cout << " Tochka to:";     l *= TO; break;
	    case 'V': cout << " Vershok to:";    l *= VE; break;
	    case 'E': cout << " Versta to:";     l *= VR;
	}

	float ar = l / AR, ce = l / CE, di = l / DI, fu = l / FU, ki = l / KI, li = l / LI, me = l / ME,
	      mi = l / MI, pi = l / PI, sa = l / SA, to = l / TO, ve = l / VE, vr = l / VR;
	cout << left << endl << "=================" << endl
	     << setw( 12 ) << "Arshin:" << ar << endl << setw( 12 ) << "Centimeter:" << ce << endl
	     << setw( 12 ) << "Diuym:" << di << endl << setw( 12 ) << "Fut:" << fu << endl
	     << setw( 12 ) << "Kilometer:" << ki << endl << setw( 12 ) << "Liniya:" << li << endl
	     << setw( 12 ) << "Meter:" << me << endl << setw( 12 ) << "Milia:" << mi << endl
	     << setw( 12 ) << "Piad:" << pi << endl << setw( 12 ) << "Sazhen:" << sa << endl
	     << setw( 12 ) << "Tochka:" << to << endl << setw( 12 ) << "Vershok:" << ve << endl
	     << setw( 12 ) << "Versta:" << vr << endl << endl << endl;
    }
private:
    const float AR, CE, DI, FU, KI, LI, ME, MI, PI, SA, TO, VE, VR;
};

int _tmain(int argc, _TCHAR* argv[])
{
    ormConverter c;
    char s; float l;
    while( true )
    {
	cout << "What unit:\n(A)rshin, (C)entimeter, (D)iuym, (F)ut\n(K)ilometer, (L)iniya, (M)eter, m(I)lia, (P)iad\n(S)azhen, (T)ochka, (V)ershok, v(E)rsta, (Q)uit\n";
	cin >> s; if( s & 32 ) s ^= 32; if( s == 'Q' ) return 0;
	cout << "Length (0 to Quit): "; cin >> l; if( l == 0 ) return 0;
	c.convert( s, l ); system( "pause" ); system( "cls" );
    }
    return 0;
}
Task: Long primes


C++: #include <iomanip>
#include <iostream>
#include <list>
using namespace std;
  
void sieve(int limit, list<int> &primes)
{
  bool *c = new bool[limit + 1];
  for (int i = 0; i <= limit; i++)
    c[i] = false;
  
  int p = 3, n = 0;
  int p2 = p * p;
  while (p2 <= limit)
  {
    for (int i = p2; i <= limit; i += 2 * p)
      c[i] = true;
    do
      p += 2;
    while (c[p]);
    p2 = p * p;
  }
  for (int i = 3; i <= limit; i += 2) 
    if (!c[i]) 
      primes.push_back(i);
  delete [] c;
}
 

int findPeriod(int n) 
{
  int r = 1, rr, period = 0;
  for (int i = 1; i <= n + 1; ++i)
    r = (10 * r) % n;
  rr = r;
  do
  {
    r = (10 * r) % n;
    period++;
  }
  while (r != rr);
  return period;
}
 
int main()
{
  int count = 0, index = 0;
  int numbers[] = {500, 1000, 2000, 4000, 8000, 16000, 32000, 64000};
  list<int> primes;
  list<int> longPrimes;
  int numberCount = sizeof(numbers) / sizeof(int);
  int *totals = new int[numberCount];
  cout << "Please wait." << endl << endl;
  sieve(64000, primes);  
  for (list<int>::iterator iterPrime = primes.begin();  
    iterPrime != primes.end(); 
    iterPrime++)
  {  
    if (findPeriod(*iterPrime) == *iterPrime - 1)
      longPrimes.push_back(*iterPrime);
  }    
  
  for (list<int>::iterator iterLongPrime = longPrimes.begin();
    iterLongPrime != longPrimes.end(); 
    iterLongPrime++)
  {
    if (*iterLongPrime > numbers[index])
      totals[index++] = count;
        ++count;
  }
  totals[numberCount - 1] = count;
  cout << "The long primes up to " << totals[0] << " are:" << endl;
  cout << "[";
  int i = 0;
  for (list<int>::iterator iterLongPrime = longPrimes.begin(); 
    iterLongPrime != longPrimes.end() && i < totals[0]; 
    iterLongPrime++, i++)
  {  
    cout << *iterLongPrime << " ";
  }  
  cout << "\b]" << endl;
  cout << endl << "The number of long primes up to:" << endl;
  for (int i = 0; i < 8; ++i)
    cout << "  " << setw(5) << numbers[i] << " is " << totals[i] << endl;
  delete [] totals;
}
Task: Vector


C++: #include <iostream>
#include <cmath>
#include <cassert>
using namespace std;

#define PI 3.14159265359

class Vector
{
public:
    Vector(double ix, double iy, char mode)
    {
        if(mode=='a')
        {
            x=ix*cos(iy);
            y=ix*sin(iy);
        }
        else
        {
            x=ix;
            y=iy;
        }
    }
    Vector(double ix,double iy)
    {
        x=ix;
        y=iy;
    }
    Vector operator+(const Vector& first)
    {
        return Vector(x+first.x,y+first.y);
    }
    Vector operator-(Vector first)
    {
        return Vector(x-first.x,y-first.y);
    }
    Vector operator*(double scalar)
    {
        return Vector(x*scalar,y*scalar);
    }
    Vector operator/(double scalar)
    {
        return Vector(x/scalar,y/scalar);
    }
    bool operator==(Vector first)
    {
        return (x==first.x&&y==first.y);
    }
    void v_print()
    {
        cout << "X: " << x << " Y: " << y;
    }
    double x,y;
};

int main()
{
    Vector vec1(0,1);
    Vector vec2(2,2);
    Vector vec3(sqrt(2),45*PI/180,'a');
    vec3.v_print();
    assert(vec1+vec2==Vector(2,3));
    assert(vec1-vec2==Vector(-2,-1));
    assert(vec1*5==Vector(0,5));
    assert(vec2/2==Vector(1,1));
    return 0;
}
Task: Special divisors


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

using uint = unsigned int;

std::vector<uint> divisors(uint n) {
    std::vector<uint> divs;
    for (uint d=1; d<=n/2; d++) {
        if (n % d == 0) divs.push_back(d);
    }
    return divs;
}

uint reverse(uint n) {
    uint r;
    for (r = 0; n; n /= 10) r = (r*10) + (n%10);
    return r;
}

bool special(uint n) {
    for (uint d : divisors(n))
        if (reverse(n) % reverse(d) != 0) return false;
    return true;
}

int main() {
    for (uint n=1, c=0; n < 200; n++) {
        if (special(n)) {
            std::cout << std::setw(4) << n;
            if (++c == 10) {
                c = 0;
                std::cout << std::endl;
            }
        }
    }
    std::cout << std::endl;
    return 0;
}
Task: Binary coded decimal


C++: #include <cassert>
#include <cstdint>
#include <iostream>

class bcd64 {
public:
    constexpr explicit bcd64(uint64_t bits = 0) : bits_(bits) {}
    constexpr bcd64& operator+=(bcd64 other) {
        uint64_t t1 = bits_ + 0x0666666666666666;
        uint64_t t2 = t1 + other.bits_;
        uint64_t t3 = t1 ^ other.bits_;
        uint64_t t4 = ~(t2 ^ t3) & 0x1111111111111110;
        uint64_t t5 = (t4 >> 2) | (t4 >> 3);
        bits_ = t2 - t5;
        return *this;
    }
    constexpr bcd64 operator-() const {
        uint64_t t1 = static_cast<uint64_t>(-static_cast<int64_t>(bits_));
        uint64_t t2 = t1 + 0xFFFFFFFFFFFFFFFF;
        uint64_t t3 = t2 ^ 1;
        uint64_t t4 = ~(t2 ^ t3) & 0x1111111111111110;
        uint64_t t5 = (t4 >> 2) | (t4 >> 3);
        return bcd64(t1 - t5);
    }
    friend constexpr bool operator==(bcd64 a, bcd64 b);
    friend std::ostream& operator<<(std::ostream& os, bcd64 a);

private:
    uint64_t bits_;
};

constexpr bool operator==(bcd64 a, bcd64 b) { return a.bits_ == b.bits_; }

constexpr bool operator!=(bcd64 a, bcd64 b) { return !(a == b); }

constexpr bcd64 operator+(bcd64 a, bcd64 b) {
    bcd64 sum(a);
    sum += b;
    return sum;
}

constexpr bcd64 operator-(bcd64 a, bcd64 b) { return a + -b; }

std::ostream& operator<<(std::ostream& os, bcd64 a) {
    auto f = os.flags();
    os << std::showbase << std::hex << a.bits_;
    os.flags(f);
    return os;
}

int main() {
    constexpr bcd64 one(0x01);
    assert(bcd64(0x19) + one == bcd64(0x20));
    std::cout << bcd64(0x19) + one << '\n';
    assert(bcd64(0x30) - one == bcd64(0x29));
    std::cout << bcd64(0x30) - one << '\n';
    assert(bcd64(0x99) + one == bcd64(0x100));
    std::cout << bcd64(0x99) + one << '\n';
}
Task: Juggler sequence


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

#include <gmpxx.h>

using big_int = mpz_class;

auto juggler(int n) {
    assert(n >= 1);
    int count = 0, max_count = 0;
    big_int a = n, max = n;
    while (a != 1) {
        if (a % 2 == 0)
            a = sqrt(a);
        else
            a = sqrt(big_int(a * a * a));
        ++count;
        if (a > max) {
            max = a;
            max_count = count;
        }
    }
    return std::make_tuple(count, max_count, max, max.get_str().size());
}

int main() {
    std::cout.imbue(std::locale(""));
    std::cout << "n    l[n]  i[n]   h[n]\n";
    std::cout << "--------------------------------\n";
    for (int n = 20; n < 40; ++n) {
        auto [count, max_count, max, digits] = juggler(n);
        std::cout << std::setw(2) << n << "    " << std::setw(2) << count
                  << "    " << std::setw(2) << max_count << "    " << max
                  << '\n';
    }
    std::cout << '\n';
    std::cout << "       n       l[n]   i[n]   d[n]\n";
    std::cout << "----------------------------------------\n";
    for (int n : {113, 173, 193, 2183, 11229, 15065, 15845, 30817, 48443,
                  275485, 1267909, 2264915, 5812827, 7110201, 56261531,
                  92502777, 172376627, 604398963}) {
        auto [count, max_count, max, digits] = juggler(n);
        std::cout << std::setw(11) << n << "    " << std::setw(3) << count
                  << "    " << std::setw(3) << max_count << "    " << digits
                  << '\n';
    }
}
Task: Odd words


C++: #include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <utility>
#include <vector>

using word_list = std::vector<std::pair<std::string, std::string>>;

void print_words(std::ostream& out, const word_list& words) {
    int n = 1;
    for (const auto& pair : words) {
        out << std::right << std::setw(2) << n++ << ": "
            << std::left << std::setw(14) << pair.first
            << pair.second << '\n';
    }
}

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;
    }
    const int min_length = 5;
    std::string line;
    std::set<std::string> dictionary;
    while (getline(in, line)) {
        if (line.size() >= min_length)
            dictionary.insert(line);
    }

    word_list odd_words, even_words;

    for (const std::string& word : dictionary) {
        if (word.size() < min_length + 2*(min_length/2))
            continue;
        std::string odd_word, even_word;
        for (auto w = word.begin(); w != word.end(); ++w) {
            odd_word += *w;
            if (++w == word.end())
                break;
            even_word += *w;
        }

        if (dictionary.find(odd_word) != dictionary.end())
            odd_words.emplace_back(word, odd_word);

        if (dictionary.find(even_word) != dictionary.end())
            even_words.emplace_back(word, even_word);
    }

    std::cout << "Odd words:\n";
    print_words(std::cout, odd_words);

    std::cout << "\nEven words:\n";
    print_words(std::cout, even_words);

    return EXIT_SUCCESS;
}
Task: Jacobsthal numbers


C++: #include <gmpxx.h>

#include <iomanip>
#include <iostream>

using big_int = mpz_class;

bool is_probably_prime(const big_int& n) {
    return mpz_probab_prime_p(n.get_mpz_t(), 30) != 0;
}

big_int jacobsthal_number(unsigned int n) {
    return ((big_int(1) << n) - (n % 2 == 0 ? 1 : -1)) / 3;
}

big_int jacobsthal_lucas_number(unsigned int n) {
    return (big_int(1) << n) + (n % 2 == 0 ? 1 : -1);
}

big_int jacobsthal_oblong_number(unsigned int n) {
    return jacobsthal_number(n) * jacobsthal_number(n + 1);
}

int main() {
    std::cout << "First 30 Jacobsthal Numbers:\n";
    for (unsigned int n = 0; n < 30; ++n) {
        std::cout << std::setw(9) << jacobsthal_number(n)
                  << ((n + 1) % 5 == 0 ? '\n' : ' ');
    }
    std::cout << "\nFirst 30 Jacobsthal-Lucas Numbers:\n";
    for (unsigned int n = 0; n < 30; ++n) {
        std::cout << std::setw(9) << jacobsthal_lucas_number(n)
                  << ((n + 1) % 5 == 0 ? '\n' : ' ');
    }
    std::cout << "\nFirst 20 Jacobsthal oblong Numbers:\n";
    for (unsigned int n = 0; n < 20; ++n) {
        std::cout << std::setw(11) << jacobsthal_oblong_number(n)
                  << ((n + 1) % 5 == 0 ? '\n' : ' ');
    }
    std::cout << "\nFirst 20 Jacobsthal primes:\n";
    for (unsigned int n = 0, count = 0; count < 20; ++n) {
        auto jn = jacobsthal_number(n);
        if (is_probably_prime(jn)) {
            ++count;
            std::cout << jn << '\n';
        }
    }
}
Task: Successive prime differences


C++: #include <iostream>
#include <cstdint>
#include <vector>
#include "prime_sieve.hpp"

using integer = uint32_t;
using vector = std::vector<integer>;

void print_vector(const vector& vec) {
    if (!vec.empty()) {
        auto i = vec.begin();
        std::cout << '(' << *i;
        for (++i; i != vec.end(); ++i)
            std::cout << ", " << *i;
        std::cout << ')';
    }
}

class diffs {
public:
    diffs(std::initializer_list<integer> list) : diffs_(list) {}
    diffs(const vector& vec) : diffs_(vec) {}
    void test_group(const vector&);
    size_t size() const {
        return diffs_.size();
    }
    void print(std::ostream&);
private:
    vector diffs_;
    vector first_;
    vector last_;
    integer count_ = 0;
};

void diffs::test_group(const vector& vec) {
    if (vec.size() < size() + 1)
        return;
    size_t start = vec.size() - size() - 1;
    for (size_t i = 0, j = start + 1; i < size(); ++i, ++j) {
        if (vec[j] - vec[j - 1] != diffs_[i])
            return;
    }
    vector group(vec.begin() + start, vec.end());
    if (count_ == 0)
        first_ = group;
    last_ = group;
    ++count_;
}

void diffs::print(std::ostream& out) {
    print_vector(diffs_);
    out << ": first group = ";
    print_vector(first_);
    out << ", last group = ";
    print_vector(last_);
    out << ", count = " << count_ << '\n';
}

int main() {
    const integer limit = 1000000;
    const size_t max_group_size = 4;
    prime_sieve sieve(limit);
    diffs d[] = { {2}, {1}, {2, 2}, {2, 4}, {4, 2}, {6, 4, 2} };
    vector group;
    for (integer p = 0; p < limit; ++p) {
        if (!sieve.is_prime(p))
            continue;
        if (group.size() >= max_group_size)
            group.erase(group.begin());
        group.push_back(p);
        for (auto&& diff : d) {
            diff.test_group(group);
        }
    }
    for (auto&& diff : d) {
        diff.print(std::cout);
    }
    return 0;
}
Task: Largest number divisible by its digits


C++: #include <iostream>
#include <sstream>
#include <set>

bool checkDec(int num) {
    std::set<int> set;

    std::stringstream ss;
    ss << num;
    auto str = ss.str();

    for (int i = 0; i < str.size(); ++i) {
        char c = str[i];
        int d = c - '0';
        if (d == 0) return false;
        if (num % d != 0) return false;
        if (set.find(d) != set.end()) {
            return false;
        }
        set.insert(d);
    }

    return true;
}

int main() {
    for (int i = 98764321; i > 0; i--) {
        if (checkDec(i)) {
            std::cout << i << "\n";
            break;
        }
    }

    return 0;
}
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;
}
Task: Sorting algorithms_Cycle sort


C++: #include <time.h>
#include <iostream>
#include <vector>

using namespace std;

class cSort
{
public:
    void doIt( vector<unsigned> s )
    {
	sq = s; display(); c_sort();
	cout << "writes: " << wr << endl; display(); 
    }
private:
    void display()
    {
	copy( sq.begin(), sq.end(), ostream_iterator<unsigned>( std::cout, " " ) );
	cout << endl;
    }
    void c_sort()
    {
	wr = 0;
	unsigned it, p, vlen = static_cast<unsigned>( sq.size() ); 
	for( unsigned c = 0; c < vlen - 1; c++ )
	{
	    it = sq[c];
	    p = c;
	    for( unsigned d = c + 1; d < vlen; d++ )
		if( sq[d] < it ) p++;

	    if( c == p ) continue;

	    doSwap( p, it );

	    while( c != p )
	    {
		p = c;
		for( unsigned e = c + 1; e < vlen; e++ )
		    if( sq[e] < it ) p++;

		doSwap( p, it );
	    }
	}
    }
    void doSwap( unsigned& p, unsigned& it )
    {
	while( sq[p] == it ) p++;
	swap( it, sq[p] );
	wr++;
    }
    vector<unsigned> sq;
    unsigned wr;
};

int main(int argc, char ** argv)
{
    srand( static_cast<unsigned>( time( NULL ) ) );
    vector<unsigned> s;
    for( int x = 0; x < 20; x++ )
	s.push_back( rand() % 100 + 21 );

    cSort c; c.doIt( s );
    return 0;
}
Task: Twin primes


C++: #include <cstdint>
#include <iostream>
#include <string>
#include <primesieve.hpp>

void print_twin_prime_count(long long limit) {
    std::cout << "Number of twin prime pairs less than " << limit
        << " is " << (limit > 0 ? primesieve::count_twins(0, limit - 1) : 0) << '\n';
}

int main(int argc, char** argv) {
    std::cout.imbue(std::locale(""));
    if (argc > 1) {
        
        
        for (int i = 1; i < argc; ++i) {
            try {
                print_twin_prime_count(std::stoll(argv[i]));
            } catch (const std::exception& ex) {
                std::cerr << "Cannot parse limit from '" << argv[i] << "'\n";
            }
        }
    } else {
        
        
        uint64_t limit = 10;
        for (int power = 1; power < 12; ++power, limit *= 10)
            print_twin_prime_count(limit);
    }
    return 0;
}
Task: Order by pair comparisons


C++: #include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

bool InteractiveCompare(const string& s1, const string& s2)
{
    if(s1 == s2) return false;  
    static int count = 0;
    string response;
    cout << "(" << ++count << ") Is " << s1 << " < " << s2 << "? ";
    getline(cin, response);
    return !response.empty() && response.front() == 'y';
}

void PrintOrder(const vector<string>& items)
{
    cout << "{ ";
    for(auto& item : items) cout << item << " ";
    cout << "}\n";
}

int main()
{
    const vector<string> items
    {
        "violet", "red", "green", "indigo", "blue", "yellow", "orange"
    };
    
    vector<string> sortedItems;
    
    
    
    for(auto& item : items)
    {
        cout << "Inserting '" << item << "' into ";
        PrintOrder(sortedItems);
        
        
        auto spotToInsert = lower_bound(sortedItems.begin(),
                                        sortedItems.end(), item, InteractiveCompare);
        sortedItems.insert(spotToInsert, item);
    }
    PrintOrder(sortedItems);
    return 0;
}
Task: Möbius function


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

constexpr int MU_MAX = 1'000'000;
std::vector<int> MU;

int mobiusFunction(int n) {
    if (!MU.empty()) {
        return MU[n];
    }

    
    MU.resize(MU_MAX + 1, 1);
    int root = sqrt(MU_MAX);

    for (int i = 2; i <= root; i++) {
        if (MU[i] == 1) {
            
            for (int j = i; j <= MU_MAX; j += i) {
                MU[j] *= -i;
            }
            
            for (int j = i * i; j <= MU_MAX; j += i * i) {
                MU[j] = 0;
            }
        }
    }

    for (int i = 2; i <= MU_MAX; i++) {
        if (MU[i] == i) {
            MU[i] = 1;
        } else if (MU[i] == -i) {
            MU[i] = -1;
        } else if (MU[i] < 0) {
            MU[i] = 1;
        } else if (MU[i] > 0) {
            MU[i] = -1;
        }
    }

    return MU[n];
}

int main() {
    std::cout << "First 199 terms of the möbius function are as follows:\n    ";
    for (int n = 1; n < 200; n++) {
        std::cout << std::setw(2) << mobiusFunction(n) << "  ";
        if ((n + 1) % 20 == 0) {
            std::cout << '\n';
        }
    }

    return 0;
}
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';
    }
}
Task: Coprimes


C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

int gcd(int a, int b) {
    int c;
    while (b) {
        c = a;
        a = b;
        b = c % b;
    }
    return a;
}

int main() {
    using intpair = std::pair<int,int>;
    std::vector<intpair> pairs = {
        {21,15}, {17,23}, {36,12}, {18,29}, {60,15}
    };
    
    pairs.erase(
        std::remove_if(
            pairs.begin(),
            pairs.end(),
            [](const intpair& x) {
                return gcd(x.first, x.second) != 1;
            }
        ),
        pairs.end()
    );
    
    for (auto& x : pairs) {
        std::cout << "{" << x.first 
                  << ", " << x.second 
                  << "}" << std::endl;
    }
    
    return 0;
}
Task: Lah numbers


C++: 

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <gmpxx.h>

using integer = mpz_class;

class unsigned_lah_numbers {
public:
    integer get(int n, int k);
private:
    std::map<std::pair<int, int>, integer> cache_;
};

integer unsigned_lah_numbers::get(int n, int k) {
    if (k == n)
        return 1;
    if (k == 0 || k > n)
        return 0;
    auto p = std::make_pair(n, k);
    auto i = cache_.find(p);
    if (i != cache_.end())
        return i->second;
    integer result = (n - 1 + k) * get(n - 1, k) + get(n - 1, k - 1);
    cache_.emplace(p, result);
    return result;
}

void print_lah_numbers(unsigned_lah_numbers& uln, int n) {
    std::cout << "Unsigned Lah numbers up to L(12,12):\nn/k";
    for (int j = 1; j <= n; ++j)
        std::cout << std::setw(11) << j;
    std::cout << '\n';
    for (int i = 1; i <= n; ++i) {
        std::cout << std::setw(2) << i << ' ';
        for (int j = 1; j <= i; ++j)
            std::cout << std::setw(11) << uln.get(i, j);
        std::cout << '\n';
    }
}

int main() {
    unsigned_lah_numbers uln;
    print_lah_numbers(uln, 12);
    std::cout << "Maximum value of L(n,k) where n == 100:\n";
    integer max = 0;
    for (int k = 0; k <= 100; ++k)
        max = std::max(max, uln.get(100, k));
    std::cout << max << '\n';
    return 0;
}