Friday, September 19, 2014

Composite Numbers Having 7


Problem

Idea : Given two integer M and N where M<=N and the value of N would be up to 1000000 .

You have to do the following tasks -

1 . Find out the composite number C where M<=C<=N .

2 . Count the composite number containing digit 7 .

3 . If there is no composite number that contains 7 , print -1 else print the number of composite number that contains 7  . 

To do the first one , you can use sieve method to indicate the composite numbers .

Then for the second one , cheak every composite number . Whether it contains 7 or not .

If yes , increase counter .

And for the last one , if the value of counter is 0 , print -1 else print the counter .

My Solution




No comments:

Post a Comment