Skip to content

Commit 9c0930c

Browse files
committed
feat(problem-1922/c): solve by following the pattern of 5 * 4 * 5 * 4 * ...
Signed-off-by: Alfi Maulana <[email protected]>
1 parent e245a56 commit 9c0930c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

old-problems/1922/c/solution.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
static long long pow(long long x, long long n);
2+
13
int countGoodNumbers(long long n) {
2-
return n;
4+
return (pow(5, n / 2 + n % 2) * pow(4, n / 2)) % 1000000007;
5+
}
6+
7+
static long long pow(long long x, long long n) {
8+
long long res = 1;
9+
while (n != 0) {
10+
if (n % 2) res = (res * x) % 1000000007;
11+
x = (x * x) % 1000000007;
12+
n /= 2;
13+
}
14+
return res;
315
}

0 commit comments

Comments
 (0)