-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1922.cpp
More file actions
33 lines (32 loc) · 751 Bytes
/
1922.cpp
File metadata and controls
33 lines (32 loc) · 751 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Solution {
public:
int countGoodNumbers(long long n) {
long long mod = 1e9 + 7;
// 2 ^ k
vector<long long> fac(51, 1);
fac[1] = 20;
for (int i = 2; i <= 50; ++i) {
fac[i] = fac[i - 1] * fac[i - 1];
fac[i] %= mod;
}
long long res = 1;
if (n & 1) {
res = 5;
n -= 1;
}
vector<bool> bits(51, false);
int index = 1;
while (n) {
if (n & 1) {
bits[index] = true;
}
index++;
n /= 2;
}
for (int i = 1; i <= 50; ++i) {
if (bits[i]) res *= fac[i - 1];
res %= mod;
}
return res;
}
};