Given a string, our task is to print the characters present at prime index.
Input : I love programming Output : lv gan Explanation : prime index characters in a string are : lv gan Input : Happy coding everyone Output : apycn ro
- Use two loops to divide the numbers upto the value of length of string.
- Increment variable result when the remainder is 0.
- If the variable result = 1, then print the corresponding character.
Below is the implementation of above approach :
For large strings, we can use Sieve of Eratosthenes to efficiently find all prime numbers smaller than or equal to length of string.
- Rearrange the given string such that all prime multiple indexes have same character
- Find the sum of the ascii values of characters which are present at prime positions
- Remove characters from the first string which are present in the second string
- Number of Positions to partition the string such that atleast m characters with same frequency are present in each substring
- Print characters having prime frequencies in order of occurrence
- XOR of Prime Frequencies of Characters in a String
- Sum and Product of Prime Frequencies of Characters in a String
- Check whether the frequencies of all the characters in a string are prime or not
- Check whether count of distinct characters in a string is Prime or not
- Count characters in a string whose ASCII values are prime
- Print all distinct characters of a string in order (3 Methods)
- Program to print first N Prime numbers
- C Program for efficiently print all prime factors of a given number
- Efficient program to print all prime factors of a given number
- Python program to print all Prime numbers in an Interval
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.
Improved By : jit_t