Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9b4b24a

Browse files
authoredApr 13, 2025··
Create 1922_Count_Good_Numbers.java
1 parent 6189808 commit 9b4b24a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
 

‎JAVA/1922_Count_Good_Numbers.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Problem Number: 1922
2+
3+
// Count Good Numbers.
4+
5+
class Solution {
6+
public int countGoodNumbers(long n) {
7+
return (int) (modPow(4 * 5, n / 2) * (n % 2 == 0 ? 1 : 5) % MOD);
8+
}
9+
10+
private static final int MOD = 1_000_000_007;
11+
12+
private long modPow(long x, long n) {
13+
if (n == 0)
14+
return 1;
15+
if (n % 2 == 1)
16+
return x * modPow(x, n - 1) % MOD;
17+
return modPow(x * x % MOD, n / 2);
18+
}
19+
}

0 commit comments

Comments
 (0)
Please sign in to comment.