Luck

A friend of mine believes a lot in fate n all. He thinks 4 and 7 are lucky digits, and all other digits are not lucky. He has a definition for lucky numbers as well. A lucky number is a number that contains only lucky digits in decimal notation. All others are unlucky as per him.

He wants to know how many lucky numbers are there between two given numbers. I want u all to help him in this.

 

Input

The input consists of several test cases. Each line of a test case consists of two numbers separated by a space: a and b. Both the numbers will be between 1 and 1,000,000,000, inclusive.

 

Output

For each input line, determine the number of lucky numbers between a and b, inclusive.

 

Sample Input

1 10

74 77

1000000 5000000

 

Sample Output

2

2

64

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Diagnostics;

 

namespace Luck

{

    class Program

    {

        static void Main(string[] args)

        {

            int a = 1000000;

            int b = 5000000;

            int count = 0;

            for (; a <= b; a++)

            {

                string str = a.ToString();

                int flag = 0;

                for (int i = 0; i < str.Length; i++)

                {

                    if (str[i].ToString() != "4")

                    {

                        if (str[i].ToString() != "7")

                        {

                            flag = 1;

                            break;

                        }

                    }

                }

                if (flag == 0)

                {

                    Console.WriteLine(a);

                    count++;

                }

            }

            Console.WriteLine("Number of lucky numbers = " + count.ToString());

        }

    }

}

Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s