Skip to content

Instantly share code, notes, and snippets.

@pascaljp
Created December 2, 2018 15:45
Show Gist options
  • Save pascaljp/554644e9000f02ed44d7b409bc223570 to your computer and use it in GitHub Desktop.
Save pascaljp/554644e9000f02ed44d7b409bc223570 to your computer and use it in GitHub Desktop.
AtCoder ABC 755
#include <iostream>
using namespace std;
int generate_and_count(long long current, long long target, bool has3, bool has5, bool has7) {
int answer = 0;
if (current > target) {
return answer;
}
if (has3 && has5 && has7) {
answer++;
}
answer += generate_and_count(current * 10 + 3, target, true, has5, has7);
answer += generate_and_count(current * 10 + 5, target, has3, true, has7);
answer += generate_and_count(current * 10 + 7, target, has3, has5, true);
return answer;
}
int main() {
int N;
cin >> N;
cout << generate_and_count(0, N, false, false, false) << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment