Skip to content

Commit 1c34927

Browse files
authored
Merge pull request #66 from InflixOP/patch1
Create #1922. Count Good Numbers.cpp
2 parents fa476b3 + 06e5d8f commit 1c34927

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

#1922. Count Good Numbers.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
int MOD = 1e9 + 7;
4+
int countGoodNumbers(long long n) {
5+
return (power(5, (n + 1) / 2) % MOD * power(4, n / 2) % MOD) % MOD;
6+
}
7+
8+
long long power(long long x, long long n) {
9+
if (n == 0)
10+
return 1;
11+
long long y = power(x, n / 2);
12+
if (n % 2 == 0) {
13+
return (y * y) % MOD;
14+
} else {
15+
return (x * y * y) % MOD;
16+
}
17+
}
18+
};

0 commit comments

Comments
 (0)