2
int mod = (int) 1e9 + 7;4
public int countGoodNumbers(long n) {6
(n % 2 == 0 ? (n / 2) : (n / 2) + 1); // deciding n/2 or n/2+1 depending on n is even or odd7
long second = n / 2; // second power would be n/2 only irrespective of even or odd8
long mul1 = power(5, first) % mod; // 5 power n/29
long mul2 = power(4, second) % mod; // 4 power n/211
ans = (ans * mul1) % mod; // computing total product12
ans = (second != 0) ? (ans * mul2) % mod : ans; // computing total product13
return (int) (ans % mod);17
long x, long y) { // this method computes pow(x,y) in O(logn) using divide & conquer19
if (y == 0) return 1; // base case (x power 0 = 1)20
temp = power(x, y / 2); // computing power for pow(x,y/2) -> divide & conquer step23
% mod; // using that result of subproblem (2 power 2 = 2 power 1 * 2 power 1)25
return (x * temp * temp)26
% mod; // using that result of subproblem (2 power 3 = 2 power 1 * 2 power 1 * 2)27
// if y is odd, x power y = x power y/2 * x power y/2 * x28
// if y is even, x power y = x power y/2 * x power y/2