Skip to content

Create 1922. Count Good Numbers #766

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions 1922. Count Good Numbers
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution {
public:
int M = 1e9+7;

long long binpow(long long a, long long b) {
a %= M;
long long res = 1;
while (b > 0) {
if (b & 1)
res = res * a % M;
a = a * a % M;
b >>= 1;
}
return res;
}

int countGoodNumbers(long long n) {
long long even_positions = (n + 1) / 2;
long long odd_positions = n / 2;
long long result = (binpow(5, even_positions) * binpow(4, odd_positions)) % M;
return result;
}
};
Loading