Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Count Good Numbers
Bookmark
Input
Small
Standard
Medium
Custom
n
=
1
each position multiplies the count
5
0
answer =
5^even × 4^odd
even index → 5 even digits · odd index → 4 primes
each position multiplies the count
5
0
answer =
5^even × 4^odd
even index → 5 even digits · odd index → 4 primes
each position multiplies the count
5
0
answer =
5^1
×
4^undefined
1
even positions, each with
5
choices {0,2,4,6,8}
each position multiplies the count
5
0
answer =
5^1
×
4^0
0
odd positions, each with
4
choices {2,3,5,7}
each position multiplies the count
5
0
answer =
5^1
×
4^0
binary exponentiation · 5^1
1
← low
base
5
result
1
compute
5^1
(exponent 1 = 1 in binary)
each position multiplies the count
5
0
answer =
5^1
×
4^0
binary exponentiation · 5^1
1
← low
base
5
result
1
result =
1
, base =
5
; read the bits of 1 low → high
each position multiplies the count
5
0
answer =
5^1
×
4^0
binary exponentiation · 5^1
1
← low
base
25
result
5
base = base² =
25
each position multiplies the count
5
0
answer =
5^1
×
4^0
binary exponentiation · 5^1
1
← low
base
25
result
5
no bits left, done
each position multiplies the count
5
0
answer =
5^1
×
4^0
5^1 =
5
each position multiplies the count
5
0
answer =
5^1
×
4^0
oddCount = 0, so 4^0 =
1
each position multiplies the count
5
0
answer =
5^1
×
4^0
=
5
×
1
answer = 5
5 × 1 mod (1e9+7) =
5
algo
master
.
io
Step:
Count good digit strings of length 1
0 / 10
Input
Small
Standard
Medium
Custom
n
=
1
0 / 10
algo
master
.
io
Step:
Count good digit strings of length 1