Skip to content

Commit e4e64d7

Browse files
authored
Create 1922. Count Good Numbers (#766)
2 parents c31d5fb + 4f5915d commit e4e64d7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Diff for: 1922. Count Good Numbers

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
int M = 1e9+7;
4+
5+
long long binpow(long long a, long long b) {
6+
a %= M;
7+
long long res = 1;
8+
while (b > 0) {
9+
if (b & 1)
10+
res = res * a % M;
11+
a = a * a % M;
12+
b >>= 1;
13+
}
14+
return res;
15+
}
16+
17+
int countGoodNumbers(long long n) {
18+
long long even_positions = (n + 1) / 2;
19+
long long odd_positions = n / 2;
20+
long long result = (binpow(5, even_positions) * binpow(4, odd_positions)) % M;
21+
return result;
22+
}
23+
};

0 commit comments

Comments
 (0)