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.
- Find the sum of the ascii values of characters which are present at prime positions
- Rearrange the given string such that all prime multiple indexes have same character
- 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
- Check whether the frequencies of all the characters in a string are prime or not
- Sum and Product of Prime Frequencies of Characters in a String
- 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
- Efficient program to print all prime factors of a given number
- Python program to print all Prime numbers in an Interval
- C Program for efficiently print all prime factors of a given number
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