Problem : 13


What is the 100th prime whose each digit is also a prime except 0 ?
Consider 1 as a prime.
Such first few primes are: 1, 2, 3, 5, 7, 11, 13, 17, 23 ……
where 1st prime is 1 and 9th prime is 23.
Note that 19 is ignored, because 9 is not a prime
Source : http://www.youngprogrammer.com/

Submit your source code as a comment. Follow the procedure :

https://tausiq.wordpress.com/2009/09/18/publish-code-in-wordpress/

Advertisements

One thought on “Problem : 13

  1. // Author : Gultu
    // Dept : CTE, UIU
    
    #include <stdio.h>
    
    bool is_prime (int x)
    {
        for ( int i = 2; i * i <= x; i++ ) {
            if ( x % i == 0 )
                return false;
        }
    
        return true;
    }
    
    
    bool prime_digit (int x)
    {
        while ( x ) {
            switch (x % 10) {
                case 4 :
                case 6 :
                case 8 :
                case 9 :
                return false;
            }
    
            x /= 10;
        }
    
        return true;
    }
    
    
    int main ()
    {
        int count = 9;
        int variable = 31;
    
        while ( count < 100 ) {
            if ( is_prime (variable) && prime_digit (variable) )
                count++;
    
            variable += 2;
        }
    
        printf ("%d\n", variable - 2);
    
        return 0;
    }
    

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