fork download
  1. #include<bits/stdc++.h>
  2. using namespace std ;
  3. #define endl "\n"
  4.  
  5. int n ;
  6. void Try(string s){
  7. int length = s.size();
  8. if(length == n ){
  9. if(s[length - 1] == '6')
  10. cout << s << endl ;
  11. return ;
  12. }
  13.  
  14. if(s[length - 1] == '8') Try(s + "6");
  15. else{
  16. if(length < 4) Try(s + "6");
  17. else if(s[length - 2] == '8' || s[length - 3] == '8') Try(s + "6");
  18. else Try(s + "8");
  19. }
  20. }
  21.  
  22. int main(){
  23. ios::sync_with_stdio(false);
  24. cin.tie(nullptr);
  25. cout.tie(nullptr);
  26.  
  27. cin >> n ;
  28. Try("8");
  29. }
Success #stdin #stdout 0.01s 5276KB
stdin
6
stdout
866686