Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How would I code this sequence in c++ for all these numbers less than 1000? Ther

ID: 3773368 • Letter: H

Question

How would I code this sequence in c++ for all these numbers less than 1000?

There are many other sieving algorithms for sequences of integers other than primes. For example, in 1955 Stanislaw Ulam generated what he called Lucky Numbers . In a list of consecutive integers beginning with 1, use the following sieving rules: Remove every second number: The second surviving number is 3. so remove every 3rd surviving number. The third surviving number is 7, so remove every 7th surviving number. The i-th surviving number is L_i. so remove every L_i-th surviving number.

Explanation / Answer

code for above logic is#include<iostream>
int main()
{
int s=1,i,j=2,k,n=100;
int a[n];//define some size not exceeding integer range
for(i=1;i<n;i++)
   std::cin>>a[i];
std::cout<<"enter how many iteration";
std::cin>>k;
while(s<k)
{
for(i=j;i<n;i=i+j)
   a[i]=a[i+1];//deletion of iterative position
n=n-n/j;//reducing array size
j=a[s+2];//next iteration element
s++;
}
for(i=1;i<n;i++)//print after completion
   std::cout<<a[i];
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote