Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If you like numbers, you may have been fascinated by prime numbers. These are numbers that have no divisors other than 1 and themselves. If we consider the primes 2 and 3, and write them in words, we write TWO and THREE. Both have a prime number of letters in their spelling. Not all prime numbers have this property. 

Write a program to count the number of primes between a given pair of integers (including the given integers if they are primes) that have a prime number of characters when written in words. The blanks are not counted when we write the numbers in words. For example, ONE HUNDRED AND THREE has only 18 characters.

Input 

One line containing two integers separated by space giving N1 and N2

Output 

One integer M giving the number of primes P such that N1 <= P <= N2 that are such that when P is written in words, it has a prime number of letters.

Constraint 

N2 <= 99999

Example 1

Input: 
1 10

Output: 
3

Explanation: 
The primes between 1 and 10 and 2, 3, 5 and 7. Of these, 5 written in words is FIVE and has a non prime number of letters and others have prime number of letters (viz TWO, THREE and SEVEN).

Example 2 
Input: 
1100 1130

Output: 
1

Explanation: 
The primes between 1100 and 1130 are 1103, 1109, 1117, 1123 and 1129. When these are written in words, we get 
ONE THOUSAND ONE HUNDRED AND THREE 
ONE THOUSAND ONE HUNDRED AND NINE 
ONE THOUSAND ONE HUNDRED AND SEVENTEEN 
ONE THOUSAND ONE HUNDRED AND TWENTY THREE 
ONE THOUSAND ONE HUNDRED AND TWENTY NINE

The count of characters in the above are 29, 28, 33, 35 and 34 
Of these only for 1103 the count of characters is prime.


What I have tried:

I DIDNT GET THE CODE PLEASE HELP ME
Posted
Updated 21-Jul-17 20:08pm

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!

If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
 
Share this answer
 
Take a sheet of paper and a pencil. Use your brain and solve the problem by hand. Since Harry Potter didn't gave you the solution, there is no magic, and the solution didn't jump to your face.
You solved the problem by following a procedure, that procedure is your algorithm. You need to write down the steps in a mechanical manner (computer like). The program will follow those steps.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

Quote:
I DIDNT GET THE CODE PLEASE HELP ME

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.

The idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements." BusinessDictionary.com[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
 
Share this answer
 
use the languages given there and write its easy mannnnnn.................
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900