Given a number ‘n’, generate the first ‘n’ terms of the Smarandache-Wellin Sequence.
The Smarandache-Wellin Sequence is a sequence formed by the Smarandache-Wellin numbers. Each Smarandache-Wellin number that make up the sequence is obtained by concatenating the consecutive prime numbers beginning from the first prime number i.e, 2. Thus, the first term of the sequence is 2, second term is 23, third term is 235, …. Similarly, the ‘n’th term is made up by concatenating the first ‘n’ prime numbers beginning from the first prime number i.e, 2.
Input : 5 Output : 2 23 235 2357 235711 Input : 10 Output : 2 23 235 2357 235711 23571113 2357111317 235711131719 23571113171923 2357111317192329
1) Initially find the first ‘n’ prime numbers and store them in a list.
2) Next, concatenate each term of the list beginning from the first term and increasing the length of the concatenated term each time by one.
3) Keep printing the concatenated terms so formed, each time, to generate the sequence.
Below is the implementation in Python.
First 5 terms of the Sequence are 2 23 235 2357 235711
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Look-and-Say Sequence
- Sum of the sequence 2, 22, 222, .........
- k-th number in the Odd-Even sequence
- Gould's Sequence
- Aronson's Sequence
- Gijswijt's Sequence
- Alcuin's Sequence
- Connell Sequence
- Find F(n) when F(i) and F(j) of a sequence are given
- Golomb sequence
- Sylvester's sequence
- Beatty sequence
- Farey Sequence
- Recaman's sequence
- Increasing sequence with given GCD
- Padovan Sequence
- Juggler Sequence
- Aliquot Sequence
- Sum of numbers from 1 to N which are in Lucas Sequence
- Euclid–Mullin Sequence
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.