Problem Statement: Consider a number n
in base-10. Find the smallest base-10 integer i
greater than n
, such that both the decimal and binary representations of i
are prime (when viewed in decimal).
Input: a number in decimal
Output: The smallest base-10 number greater than n
, which when viewed in both binary and decimal, is prime.
Examples:
Input:
- 1
- 3
- 100
- 1234567
Output:
- 3
- 5
- 101
- 1234721
Explanations:
- 3 is prime. 3 in binary is 11, which is also prime. 3 is the smallest number larger than 1 which satisfies these properties.
- 5 is prime. 5 in binary is 101, which is also prime. 5 is the smallest number larger than 3 which satisfies these properties.
- 101 is prime. 101 in binary is 1100101, which is also prime. 101 is the smallest number larger than 100 which satisfies these properties.
- 1234721 is prime. 1234721 in binary is 100101101011100100001, which is also prime. 1234721 is the smallest number larger than 1234567 which satisfies these properties.
Here are your test cases, ordered in ascending difficulty according to my own naive implementation. Please include a Try it online! in your answer:
Input:
n = 1325584480535587277061226381983816
, a.k.a.(((((((1 + 2) * 3) ** 4) + 5) * 6) ** 7) + 8) * 9
n = 1797010299914431210413179829509605039731475627537851106401
, a.k.a((3^4)^5)^6
n = 2601281349055093346554910065262730566475782
, a.k.a0^0 + 1^1 + 2^2 + ... + 28^28 + 29^29
n = 20935051082417771847631371547939998232420940314
, a.k.a.0! + 1! + ... + 38! + 39!
n = 123456789101112131415161718192021222324252627282930
Output:
1325584480535587277061226381986899
1797010299914431210413179829509605039731475627537851115949
2601281349055093346554910065262730566501899
20935051082417771847631371547939998232420981273
123456789101112131415161718192021222324252627319639
If you manage to get the correct outputs for these 5 test cases in under 3 seconds total, your code can be considered. This is code-golf, the shortest code in bytes wins.