mirror of https://github.com/doocs/leetcode.git
19 lines
437 B
Java
19 lines
437 B
Java
class Solution {
|
|
private final int mod = (int) 1e9 + 7;
|
|
|
|
public int countGoodNumbers(long n) {
|
|
return (int) (qpow(5, (n + 1) >> 1) * qpow(4, n >> 1) % mod);
|
|
}
|
|
|
|
private long qpow(long x, long n) {
|
|
long res = 1;
|
|
while (n != 0) {
|
|
if ((n & 1) == 1) {
|
|
res = res * x % mod;
|
|
}
|
|
x = x * x % mod;
|
|
n >>= 1;
|
|
}
|
|
return res;
|
|
}
|
|
} |