Composite digits

Which is the smallest prime number whose digits are composite?


The answer is 89.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Caleb Townsend
Mar 27, 2015

The only single digit composite numbers are 4 , 6 , 8 , 4, 6, 8, and 9. 9. Then the number we are looking for obviously ends in 9 9 ; it is divisible by 2 2 otherwise. So checking the first few possibilities, 49 = 7 2 (not prime) 69 = 3 × 23 (not prime) 89 is prime 49 = 7^2 \text{ (not prime)} \\ 69 = 3\times 23 \text{ (not prime)} \\ \boxed{89\text{ is prime}} and is therefore the smallest prime number with composite digits.

Aryan Gaikwad
Mar 27, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public static void main(String args[]){
    for(int i = 2;; i++)
        if(prime(i) && chk(Integer.toString(i)))
            System.out.println(i);
}

static boolean prime(int n) {
    if(n == 2) return true;
    if (n % 2 == 0) return false;
    for(int i = 3; i * i <= n; i += 2)
        if(n % i == 0) return false;
    return true;
}

static boolean chk(String n){
    boolean m = true;
    for(int i = 0; i < n.length(); i++)
        if(prime(Character.getNumericValue(n.charAt(i)))){
            m = false;
            break;
        }
    return m;
}

Execution time ~ 0.00028 seconds

Well nice solution ,but will the break at Line 5 work ? There's no Loop or Switch being used there .

EDIT: The error being reported on my Laptop says the same too .

A Former Brilliant Member - 6 years, 2 months ago

Log in to reply

It won't. I forgot to include the break in curly braces. Thanks for pointing it out!

Aryan Gaikwad - 6 years, 2 months ago
Bill Bell
Sep 26, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from gmpy2 import next_prime, is_prime

p=2
while True:
    p=next_prime(p)
    fail=True
    for d in map(int,list(str(p))):
        if d==1 or is_prime(d):
            break
    else:
        fail=False
    if not fail:
        print p
        break

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...