Created
December 2, 2018 15:45
-
-
Save pascaljp/554644e9000f02ed44d7b409bc223570 to your computer and use it in GitHub Desktop.
AtCoder ABC 755
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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