WeixiangYan/CodeTransOcean huggingface dataset:
Task: Calkin-Wilf sequence


C++: #include <iostream>
#include <vector>
#include <boost/rational.hpp>

using rational = boost::rational<unsigned long>;

unsigned long floor(const rational& r) {
    return r.numerator()/r.denominator();
}

rational calkin_wilf_next(const rational& term) {
    return 1UL/(2UL * floor(term) + 1UL - term);
}

std::vector<unsigned long> continued_fraction(const rational& r) {
    unsigned long a = r.numerator();
    unsigned long b = r.denominator();
    std::vector<unsigned long> result;
    do {
        result.push_back(a/b);
        unsigned long c = a;
        a = b;
        b = c % b;
    } while (a != 1);
    if (result.size() > 0 && result.size() % 2 == 0) {
        --result.back();
        result.push_back(1);
    }
    return result;
}

unsigned long term_number(const rational& r) {
    unsigned long result = 0;
    unsigned long d = 1;
    unsigned long p = 0;
    for (unsigned long n : continued_fraction(r)) {
        for (unsigned long i = 0; i < n; ++i, ++p)
            result |= (d << p);
        d = !d;
    }
    return result;
}

int main() {
    rational term = 1;
    std::cout << "First 20 terms of the Calkin-Wilf sequence are:\n";
    for (int i = 1; i <= 20; ++i) {
        std::cout << std::setw(2) << i << ": " << term << '\n';
        term = calkin_wilf_next(term);
    }
    rational r(83116, 51639);
    std::cout << r << " is the " << term_number(r) << "th term of the sequence.\n";
}
Task: Read a file character by character_UTF8


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

using namespace std;
 
int main(void)
{
    
    std::locale::global(std::locale("")); 
    std::cout.imbue(std::locale());
    ifstream in("input.txt");
 
    wchar_t c;
    while ((c = in.get()) != in.eof())
        wcout<<c;
    in.close();
 
    return EXIT_SUCCESS;
}
Task: Sorting Algorithms_Circle Sort


C++: #include <iostream>

int circlesort(int* arr, int lo, int hi, int swaps) {
    if(lo == hi) {
        return swaps;
    }
    int high = hi;
    int low = lo;
    int mid = (high - low) / 2;
    while(lo < hi) {
        if(arr[lo] > arr[hi]) {
            int temp = arr[lo];
            arr[lo] = arr[hi];
            arr[hi] = temp;
            swaps++;
        }
        lo++;
        hi--;
    }

    if(lo == hi) {
        if(arr[lo] > arr[hi+1]) {
            int temp = arr[lo];
            arr[lo] = arr[hi+1];
            arr[hi+1] = temp;
            swaps++;
        }
    }
    swaps = circlesort(arr, low, low+mid, swaps);
    swaps = circlesort(arr, low+mid+1, high, swaps);
    return swaps;
}

void circlesortDriver(int* arr, int n) {
    do {
        for(int i = 0; i < n; i++) {
            std::cout << arr[i] << ' ';
        }
        std::cout << std::endl;
    } while(circlesort(arr, 0, n-1, 0));
}

int main() {
    int arr[] = { 6, 7, 8, 9, 2, 5, 3, 4, 1 };
    circlesortDriver(arr, sizeof(arr)/sizeof(int));
    return 0;
}
Task: Penney's game


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

using namespace std;

class penney
{
public:
    penney()
    { pW = cW = 0;  }
    void gameLoop()
    {
	string a;
	while( true )
	{
	    playerChoice = computerChoice = "";
	    if( rand() % 2 ) 
	    { computer(); player(); }
	    else
	    { player(); computer(); }

	    play();

	    cout << "[Y] to play again "; cin >> a;
	    if( a[0] != 'Y' && a[0] != 'y' ) 
	    {
		cout << "Computer won " << cW << " times." << endl << "Player won " << pW << " times.";
		break;
	    }
	    cout << endl << endl;
        }
    }
private:
    void computer()
    {
        if( playerChoice.length() == 0 )
	{
	    for( int x = 0; x < 3; x++ )
		computerChoice.append( ( rand() % 2 ) ? "H" : "T", 1 );	
	}
	else
	{
	    computerChoice.append( playerChoice[1] == 'T' ? "H" : "T", 1 );
	    computerChoice += playerChoice.substr( 0, 2 );
	}
	cout << "Computer's sequence of three is: " << computerChoice << endl;
    }
    void player()
    {
	cout << "Enter your sequence of three (H/T) "; cin >> playerChoice;
    }
    void play()
    {
	sequence = "";
	while( true )
	{
	    sequence.append( ( rand() % 2 ) ? "H" : "T", 1 );
	    if( sequence.find( playerChoice ) != sequence.npos )
	    {
		showWinner( 1 );
		break;
	    }
	    else if( sequence.find( computerChoice ) != sequence.npos )
	    {
		showWinner( 0 );
		break;
	    }
	}
    }
    void showWinner( int i )
    {
	string s;
	if( i ) { s = "Player wins!"; pW++; }
	else { s = "Computer wins!"; cW++; }
	cout << "Tossed sequence: " << sequence << endl << s << endl << endl;
    }
    string playerChoice, computerChoice, sequence;
    int pW, cW;
};
int main( int argc, char* argv[] )
{
    srand( static_cast<unsigned>( time( NULL ) ) );
    penney game; game.gameLoop();
    return 0;
}
Task: Musical scale


C++: #include <iostream>
#include <windows.h>
#include <mmsystem.h>

#pragma comment ( lib, "winmm.lib" )

typedef unsigned char byte;

typedef union 
{ 
    unsigned long word; 
    unsigned char data[4]; 
}
midi_msg;

class midi
{
public:
    midi()
    {
	if( midiOutOpen( &device, 0, 0, 0, CALLBACK_NULL) != MMSYSERR_NOERROR ) 
	{
	    std::cout << "Error opening MIDI Output..." << std::endl;
	    device = 0;
	}
    }
    ~midi()
    {
	midiOutReset( device );
	midiOutClose( device );
    }
    bool isOpen() { return device != 0; }
    void setInstrument( byte i )
    {
	message.data[0] = 0xc0; message.data[1] = i;
	message.data[2] = 0; message.data[3] = 0;
	midiOutShortMsg( device, message.word );
    }
    void playNote( byte n, unsigned i )
    {
	playNote( n ); Sleep( i ); stopNote( n );
    }

private:
    void playNote( byte n )
    {
	message.data[0] = 0x90; message.data[1] = n;
	message.data[2] = 127; message.data[3] = 0;
	midiOutShortMsg( device, message.word );
    }
    void stopNote( byte n )
    {
	message.data[0] = 0x90; message.data[1] = n;
	message.data[2] = 0; message.data[3] = 0;
	midiOutShortMsg( device, message.word );
    }
    HMIDIOUT device;
    midi_msg message;
};

int main( int argc, char* argv[] )
{
    midi m;
    if( m.isOpen() )
    {
	byte notes[] = { 60, 62, 64, 65, 67, 69, 71, 72 };
	m.setInstrument( 42 );
	for( int x = 0; x < 8; x++ )
	    m.playNote( notes[x], rand() % 100 + 158 );
	Sleep( 1000 );
    }
    return 0;
}
Task: Sorting algorithms_Strand sort


C++: #include <list>

template <typename T>
std::list<T> strandSort(std::list<T> lst) {
  if (lst.size() <= 1)
    return lst;
  std::list<T> result;
  std::list<T> sorted;
  while (!lst.empty()) {
    sorted.push_back(lst.front());
    lst.pop_front();
    for (typename std::list<T>::iterator it = lst.begin(); it != lst.end(); ) {
      if (sorted.back() <= *it) {
        sorted.push_back(*it);
        it = lst.erase(it);
      } else
        it++;
    }
    result.merge(sorted);
  }
  return result;
}
Task: Abelian sandpile model


C++: #include <iostream>
#include "xtensor/xarray.hpp"
#include "xtensor/xio.hpp"
#include "xtensor-io/ximage.hpp"

xt::xarray<int> init_grid (unsigned long x_dim, unsigned long y_dim)
{
    xt::xarray<int>::shape_type shape = { x_dim, y_dim };
    xt::xarray<int> grid(shape);

    grid(x_dim/2, y_dim/2) = 64000;
    
    return grid;
}

int print_grid(xt::xarray<int>& grid)
{
    
    
    

    
    xt::dump_image("grid.jpg", grid);

    return 0;
}

bool iterate_grid(xt::xarray<int>& grid, const unsigned long& x_dim, const unsigned long& y_dim)
{
    bool changed = false;

    for (unsigned long i=0; i < x_dim; ++i)
    {
        for (unsigned long j=0; j < y_dim; ++j)
        {
            if ( grid(i, j) >= 4 )
            {
                grid(i, j) -= 4;
                changed = true;
                try
                {
                    grid.at(i-1, j) += 1;
                    grid.at(i+1, j) += 1;
                    grid.at(i, j-1) += 1;
                    grid.at(i, j+1) += 1;
                }
                catch (const std::out_of_range& oor)
                {
                }
            }
        }
    }

    return changed;
}

int main(int argc, char* argv[])
{
    const unsigned long x_dim { 200 };
    const unsigned long y_dim { 200 };

    xt::xarray<int> grid = init_grid(x_dim, y_dim);
    bool changed { true };

    iterate_grid(grid, x_dim, y_dim);

    while (changed == true)
    {
        changed = iterate_grid(grid, x_dim, y_dim);
    }
    print_grid(grid);

    return 0;
}
Task: Respond to an unknown method call


C++: class animal {
public:
  virtual void bark() 
  {
    throw "implement me: do not know how to bark";
  }
};

class elephant : public animal 
{
};

int main()
{
  elephant e;
  e.bark();  
}
Task: Farey sequence


C++: #include <iostream>

struct fraction {
    fraction(int n, int d) : numerator(n), denominator(d) {}
    int numerator;
    int denominator;
};

std::ostream& operator<<(std::ostream& out, const fraction& f) {
    out << f.numerator << '/' << f.denominator;
    return out;
}

class farey_sequence {
public:
    explicit farey_sequence(int n) : n_(n), a_(0), b_(1), c_(1), d_(n) {}
    fraction next() {
        
        fraction result(a_, b_);
        int k = (n_ + b_)/d_;
        int next_c = k * c_ - a_;
        int next_d = k * d_ - b_;
        a_ = c_;
        b_ = d_;
        c_ = next_c;
        d_ = next_d;
        return result;
    }
    bool has_next() const { return a_ <= n_; }
private:
    int n_, a_, b_, c_, d_;
};

int main() {
    for (int n = 1; n <= 11; ++n) {
        farey_sequence seq(n);
        std::cout << n << ": " << seq.next();
        while (seq.has_next())
            std::cout << ' ' << seq.next();
        std::cout << '\n';
    }
    for (int n = 100; n <= 1000; n += 100) {
        int count = 0;
        for (farey_sequence seq(n); seq.has_next(); seq.next())
            ++count;
        std::cout << n << ": " << count << '\n';
    }
    return 0;
}
Task: Implicit type conversion


C++: #include <iostream>
#include <math.h>

struct PolarPoint;


struct CartesianPoint
{
    double x;
    double y;
    
    
    operator PolarPoint();
};


struct PolarPoint
{
    double rho;
    double theta;
    
    
    operator CartesianPoint();
};


CartesianPoint::operator PolarPoint()
{
    return PolarPoint
    {
        sqrt(x*x + y*y),
        atan2(y, x)
    };
}


PolarPoint::operator CartesianPoint()
{
    return CartesianPoint 
    {
        rho * cos(theta),
        rho * sin(theta)
    };
}

int main()
{
    
    CartesianPoint cp1{2,-2};
    
    PolarPoint pp1 = cp1;
    
    CartesianPoint cp2 = pp1;
    
    std::cout << "rho=" << pp1.rho << ", theta=" << pp1.theta << "\n"; 
    std::cout << "x=" << cp2.x << ", y=" << cp2.y << "\n"; 
}
Task: Magnanimous numbers


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

bool is_prime(unsigned int n) {
    if (n < 2)
        return false;
    if (n % 2 == 0)
        return n == 2;
    if (n % 3 == 0)
        return n == 3;
    for (unsigned int p = 5; p * p <= n; p += 4) {
        if (n % p == 0)
            return false;
        p += 2;
        if (n % p == 0)
            return false;
    }
    return true;
}

bool is_magnanimous(unsigned int n) {
    for (unsigned int p = 10; n >= p; p *= 10) {
        if (!is_prime(n % p + n / p))
            return false;
    }
    return true;
}

int main() {
    unsigned int count = 0, n = 0;
    std::cout << "First 45 magnanimous numbers:\n";
    for (; count < 45; ++n) {
        if (is_magnanimous(n)) {
            if (count > 0)
                std::cout << (count % 15 == 0 ? "\n" : ", ");
            std::cout << std::setw(3) << n;
            ++count;
        }
    }
    std::cout << "\n\n241st through 250th magnanimous numbers:\n";
    for (unsigned int i = 0; count < 250; ++n) {
        if (is_magnanimous(n)) {
            if (count++ >= 240) {
                if (i++ > 0)
                    std::cout << ", ";
                std::cout << n;
            }
        }
    }
    std::cout << "\n\n391st through 400th magnanimous numbers:\n";
    for (unsigned int i = 0; count < 400; ++n) {
        if (is_magnanimous(n)) {
            if (count++ >= 390) {
                if (i++ > 0)
                    std::cout << ", ";
                std::cout << n;
            }
        }
    }
    std::cout << '\n';
    return 0;
}
Task: Sexy primes


C++: #include <array>
#include <iostream>
#include <vector>
#include <boost/circular_buffer.hpp>
#include "prime_sieve.hpp"

int main() {
    using std::cout;
    using std::vector;
    using boost::circular_buffer;
    using group_buffer = circular_buffer<vector<int>>;

    const int max = 1000035;
    const int max_group_size = 5;
    const int diff = 6;
    const int array_size = max + diff;
    const int max_groups = 5;
    const int max_unsexy = 10;

    
    prime_sieve sieve(array_size);

    std::array<int, max_group_size> group_count{0};
    vector<group_buffer> groups(max_group_size, group_buffer(max_groups));
    int unsexy_count = 0;
    circular_buffer<int> unsexy_primes(max_unsexy);
    vector<int> group;

    for (int p = 2; p < max; ++p) {
        if (!sieve.is_prime(p))
            continue;
        if (!sieve.is_prime(p + diff) && (p - diff < 2 || !sieve.is_prime(p - diff))) {
            
            ++unsexy_count;
            unsexy_primes.push_back(p);
        } else {
            
            group.clear();
            group.push_back(p);
            for (int group_size = 1; group_size < max_group_size; group_size++) {
                int next_p = p + group_size * diff;
                if (next_p >= max || !sieve.is_prime(next_p))
                    break;
                group.push_back(next_p);
                ++group_count[group_size];
                groups[group_size].push_back(group);
            }
        }
    }

    for (int size = 1; size < max_group_size; ++size) {
        cout << "number of groups of size " << size + 1 << " is " << group_count[size] << '\n';
        cout << "last " << groups[size].size() << " groups of size " << size + 1 << ":";
        for (const vector<int>& group : groups[size]) {
            cout << " (";
            for (size_t i = 0; i < group.size(); ++i) {
                if (i > 0)
                    cout << ' ';
                cout << group[i];
            }
            cout << ")";
        }
        cout << "\n\n";
    }
    cout << "number of unsexy primes is " << unsexy_count << '\n';
    cout << "last " << unsexy_primes.size() << " unsexy primes:";
    for (int prime : unsexy_primes)
        cout << ' ' << prime;
    cout << '\n';
    return 0;
}
Task: Taxicab numbers


C++: #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <sstream>
#include <vector>

template <typename T>
size_t indexOf(const std::vector<T> &v, const T &k) {
    auto it = std::find(v.cbegin(), v.cend(), k);

    if (it != v.cend()) {
        return it - v.cbegin();
    }
    return -1;
}

int main() {
    std::vector<size_t> cubes;

    auto dump = [&cubes](const std::string &title, const std::map<int, size_t> &items) {
        std::cout << title;
        for (auto &item : items) {
            std::cout << "\n" << std::setw(4) << item.first << " " << std::setw(10) << item.second;
            for (auto x : cubes) {
                auto y = item.second - x;
                if (y < x) {
                    break;
                }
                if (std::count(cubes.begin(), cubes.end(), y)) {
                    std::cout << " = " << std::setw(4) << indexOf(cubes, y) << "^3 + " << std::setw(3) << indexOf(cubes, x) << "^3";
                }
            }
        }
    };

    std::vector<size_t> sums;

    
    for (size_t i = 0; i < 1190; i++) {
        auto cube = i * i * i;
        cubes.push_back(cube);
        for (auto j : cubes) {
            sums.push_back(cube + j);
        }
    }
    std::sort(sums.begin(), sums.end());

    
    auto nm1 = sums[0];
    auto n = sums[1];
    int idx = 0;
    std::map<int, size_t> task;
    std::map<int, size_t> trips;

    auto it = sums.cbegin();
    auto end = sums.cend();
    it++;
    it++;

    while (it != end) {
        auto np1 = *it;

        if (nm1 == np1) {
            trips.emplace(idx, n);
        }
        if (nm1 != n && n == np1) {
            if (++idx <= 25 || idx >= 2000 == idx <= 2006) {
                task.emplace(idx, n);
            }
        }
        nm1 = n;
        n = np1;

        it++;
    }

    dump("First 25 Taxicab Numbers, the 2000th, plus the next half-dozen:", task);

    std::stringstream ss;
    ss << "\n\nFound " << trips.size() << " triple Taxicabs under 2007:";
    dump(ss.str(), trips);

    return 0;
}
Task: Strong and weak primes


C++: #include <algorithm>
#include <iostream>
#include <iterator>
#include <locale>
#include <vector>
#include "prime_sieve.hpp"

const int limit1 = 1000000;
const int limit2 = 10000000;

class prime_info {
public:
    explicit prime_info(int max) : max_print(max) {}
    void add_prime(int prime);
    void print(std::ostream& os, const char* name) const;
private:
    int max_print;
    int count1 = 0;
    int count2 = 0;
    std::vector<int> primes;
};

void prime_info::add_prime(int prime) {
    ++count2;
    if (prime < limit1)
        ++count1;
    if (count2 <= max_print)
        primes.push_back(prime);
}

void prime_info::print(std::ostream& os, const char* name) const {
    os << "First " << max_print << " " << name << " primes: ";
    std::copy(primes.begin(), primes.end(), std::ostream_iterator<int>(os, " "));
    os << '\n';
    os << "Number of " << name << " primes below " << limit1 << ": " << count1 << '\n';
    os << "Number of " << name << " primes below " << limit2 << ": " << count2 << '\n';
}

int main() {
    prime_sieve sieve(limit2 + 100);

    
    std::cout.imbue(std::locale(""));

    
    prime_info strong_primes(36);
    prime_info weak_primes(37);
    int p1 = 2, p2 = 3;
    for (int p3 = 5; p2 < limit2; ++p3) {
        if (!sieve.is_prime(p3))
            continue;
        int diff = p1 + p3 - 2 * p2;
        if (diff < 0)
            strong_primes.add_prime(p2);
        else if (diff > 0)
            weak_primes.add_prime(p2);
        p1 = p2;
        p2 = p3;
    }
    strong_primes.print(std::cout, "strong");
    weak_primes.print(std::cout, "weak");
    return 0;
}
Task: Strange unique prime triplets


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

std::vector<bool> prime_sieve(size_t limit) {
    std::vector<bool> sieve(limit, true);
    if (limit > 0)
        sieve[0] = false;
    if (limit > 1)
        sieve[1] = false;
    for (size_t i = 4; i < limit; i += 2)
        sieve[i] = false;
    for (size_t p = 3; ; p += 2) {
        size_t q = p * p;
        if (q >= limit)
            break;
        if (sieve[p]) {
            size_t inc = 2 * p;
            for (; q < limit; q += inc)
                sieve[q] = false;
        }
    }
    return sieve;
}

void strange_unique_prime_triplets(int limit, bool verbose) {
    std::vector<bool> sieve = prime_sieve(limit * 3);
    std::vector<int> primes;
    for (int p = 3; p < limit; p += 2) {
        if (sieve[p])
            primes.push_back(p);
    }
    size_t n = primes.size();
    size_t count = 0;
    if (verbose)
        std::cout << "Strange unique prime triplets < " << limit << ":\n";
    for (size_t i = 0; i + 2 < n; ++i) {
        for (size_t j = i + 1; j + 1 < n; ++j) {
            for (size_t k = j + 1; k < n; ++k) {
                int sum = primes[i] + primes[j] + primes[k];
                if (sieve[sum]) {
                    ++count;
                    if (verbose) {
                        std::cout << std::setw(2) << primes[i] << " + "
                                  << std::setw(2) << primes[j] << " + "
                                  << std::setw(2) << primes[k] << " = " << sum
                                  << '\n';
                    }
                }
            }
        }
    }
    std::cout << "\nCount of strange unique prime triplets < " << limit
              << " is " << count << ".\n";
}

int main() {
    strange_unique_prime_triplets(30, true);
    strange_unique_prime_triplets(1000, false);
    return 0;
}
Task: Strange plus numbers


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

const std::vector<bool> p{
    false, false, true,  true,  false,
    true,  false, true,  false, false,
    false, true,  false, true,  false,
    false, false, true,  false
};

bool isStrange(long n) {
    if (n < 10) {
        return false;
    }
    for (; n >= 10; n /= 10) {
        if (!p[n % 10 + (n / 10) % 10]) {
            return false;
        }
    }
    return true;
}

void test(int nMin, int nMax) {
    int k = 0;

    for (long n = nMin; n <= nMax;n++) {
        if (isStrange(n)) {
            std::cout << n;
            if (++k % 10 != 0) {
                std::cout << ' ';
            } else {
                std::cout << '\n';
            }
        }
    }
}

int main() {
    test(101, 499);
    return 0;
}
Task: Smarandache prime-digital sequence


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

using integer = uint32_t;

integer next_prime_digit_number(integer n) {
    if (n == 0)
        return 2;
    switch (n % 10) {
    case 2:
        return n + 1;
    case 3:
    case 5:
        return n + 2;
    default:
        return 2 + next_prime_digit_number(n/10) * 10;
    }
}

bool is_prime(integer n) {
    if (n < 2)
        return false;
    if (n % 2 == 0)
        return n == 2;
    if (n % 3 == 0)
        return n == 3;
    if (n % 5 == 0)
        return n == 5;
    constexpr integer wheel[] = { 4,2,4,2,4,6,2,6 };
    integer p = 7;
    for (;;) {
        for (integer w : wheel) {
            if (p * p > n)
                return true;
            if (n % p == 0)
                return false;
            p += w;
        }
    }
}

int main() {
    std::cout.imbue(std::locale(""));
    const integer limit = 1000000000;
    integer n = 0, max = 0;
    std::cout << "First 25 SPDS primes:\n";
    for (int i = 0; n < limit; ) {
        n = next_prime_digit_number(n);
        if (!is_prime(n))
            continue;
        if (i < 25) {
            if (i > 0)
                std::cout << ' ';
            std::cout << n;
        }
        else if (i == 25)
            std::cout << '\n';
        ++i;
        if (i == 100)
            std::cout << "Hundredth SPDS prime: " << n << '\n';
        else if (i == 1000)
            std::cout << "Thousandth SPDS prime: " << n << '\n';
        else if (i == 10000)
            std::cout << "Ten thousandth SPDS prime: " << n << '\n';
        max = n;
    }
    std::cout << "Largest SPDS prime less than " << limit << ": " << max << '\n';
    return 0;
}
Task: Square-free integers


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

using integer = uint64_t;

bool square_free(integer n) {
    if (n % 4 == 0)
        return false;
    for (integer p = 3; p * p <= n; p += 2) {
        integer count = 0;
        for (; n % p == 0; n /= p) {
            if (++count > 1)
                return false;
        }
    }
    return true;
}

void print_square_free_numbers(integer from, integer to) {
    std::cout << "Square-free numbers between " << from
        << " and " << to << ":\n";
    std::string line;
    for (integer i = from; i <= to; ++i) {
        if (square_free(i)) {
            if (!line.empty())
                line += ' ';
            line += std::to_string(i);
            if (line.size() >= 80) {
                std::cout << line << '\n';
                line.clear();
            }
        }
    }
    if (!line.empty())
        std::cout << line << '\n';
}

void print_square_free_count(integer from, integer to) {
    integer count = 0;
    for (integer i = from; i <= to; ++i) {
        if (square_free(i))
            ++count;
    }
    std::cout << "Number of square-free numbers between "
        << from << " and " << to << ": " << count << '\n';
}

int main() {
    print_square_free_numbers(1, 145);
    print_square_free_numbers(1000000000000LL, 1000000000145LL);
    print_square_free_count(1, 100);
    print_square_free_count(1, 1000);
    print_square_free_count(1, 10000);
    print_square_free_count(1, 100000);
    print_square_free_count(1, 1000000);
    return 0;
}