lucky numbers Algorithm

The lucky numbers algorithm is a unique and interesting method used to identify a sequence of numbers that share specific mathematical properties, in a similar vein to prime numbers. These numbers are called "lucky numbers" as they were first introduced by the Hungarian mathematician Stanislaw Ulam in 1955, who noticed a pattern while playing a solitaire game. The algorithm starts with a list of positive integers, and iteratively removes every nth number from the list, where n is the next remaining number in the sequence. As a result, the algorithm produces a series of numbers that are "lucky" because they have survived multiple rounds of elimination. To generate lucky numbers using the algorithm, start by creating a list of positive integers beginning with 1. Then, eliminate every second number, leaving only the odd integers. The second surviving number on the list is 3, so in the next step, eliminate every third number from the remaining list. The next surviving number is 7, so remove every seventh number, and so on. This process is continued indefinitely, with the remaining numbers being labeled as "lucky." The first few lucky numbers generated using this algorithm are 1, 3, 7, 9, 13, 15, 21, and so forth. While the lucky numbers algorithm produces an intriguing sequence of numbers, its practical applications are limited, serving primarily as a curious mathematical phenomenon.
//
// Lucky Numbers Implementation in C++
//
// The All ▲lgorithms Project
//
// https://allalgorithms.com/math
// https://github.com/allalgorithms/cpp
//
// Contributed by: Sathwik Matsa
// Github: @sathwikmatsa
//
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

// returns a vector of int containing lucky numbers in range [1,n]
vector <int> lucky_numbers(int n){

	vector <int> seive;

	// store numbers from 1 to n in the vector
	for(int i = 1; i<=n; i++){
		seive.push_back(i);
	}

	int survivor = 1;
	int delete_every = 2;
	int index;
	while(seive.size() >= delete_every){
		index = delete_every-1;
		while(index < seive.size()){
			seive.erase(seive.begin()+index);
			index+=(delete_every-1);
		}
		delete_every = survivor = (*(++find(seive.begin(), seive.end(), survivor)));
	}

	return seive;
}

int main(){
	int n;
	cout << "Enter a number: ";
	cin>>n;
	vector <int> luckyNumbers = lucky_numbers(n);
	cout << "lucky numbers up to " << n << ":" <<endl;
	for ( vector<int>::iterator it = luckyNumbers.begin() ; it < luckyNumbers.end(); it++ ){
		cout << *it << " ";
	}
	cout<<endl;
	return 0;
}

LANGUAGE:

DARK MODE: