Problem p03212 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {

  int n;
  cin >> n;

  if (n < 357) {
    puts("0");
    return 0;
  }

  int ans = 0;

  for (int i = 357; i <= n; i += 2) {
    int temp = i;
    bool while_flag = true;
    bool count3 = false;
    bool count5 = false;
    bool count7 = false;
    switch (temp % 100) {
    case 33:
      count3 = true;
      break;
    case 35:
      count3 = true;
      count5 = true;
      break;
    case 37:
      count3 = true;
      count7 = true;
      break;
    case 53:
      count5 = true;
      count3 = true;
      break;
    case 55:
      count5 = true;
      break;
    case 57:
      count5 = true;
      count7 = true;
      break;
    case 73:
      count7 = true;
      count3 = true;
      break;
    case 75:
      count7 = true;
      count5 = true;
      break;
    case 77:
      count7 = true;
      break;
    default:
      while_flag = false;
      break;
    }
    temp /= 100;
    while (temp && while_flag) {
      switch (temp % 10) {
      case 3:
        count3 = true;
        break;
      case 5:
        count5 = true;
        break;
      case 7:
        count7 = true;
        break;
      default:
        while_flag = false;
        break;
      }
      if (!while_flag)
        break;
      temp /= 10;
    }
    if (while_flag && count3 && count5 && count7) {
      // cout << i << endl;
      ans++;
    }
    if (i % 10 == 7) {
      i += 4;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {

  int n;
  cin >> n;

  if (n < 357) {
    puts("0");
    return 0;
  }

  int ans = 0;

  for (int i = 357; i <= n; i += 2) {
    int temp = i;
    bool while_flag = true;
    bool count3 = false;
    bool count5 = false;
    bool count7 = false;
    switch (temp % 100) {
    case 33:
      count3 = true;
      break;
    case 35:
      count3 = true;
      count5 = true;
      break;
    case 37:
      count3 = true;
      count7 = true;
      break;
    case 53:
      count5 = true;
      count3 = true;
      break;
    case 55:
      count5 = true;
      break;
    case 57:
      count5 = true;
      count7 = true;
      break;
    case 73:
      count7 = true;
      count3 = true;
      break;
    case 75:
      count7 = true;
      count5 = true;
      break;
    case 77:
      count7 = true;
      break;
    default:
      while_flag = false;
      break;
    }
    temp /= 100;
    while (temp && while_flag) {
      switch (temp % 10) {
      case 3:
        count3 = true;
        break;
      case 5:
        count5 = true;
        break;
      case 7:
        count7 = true;
        break;
      default:
        while_flag = false;
        break;
      }
      if (!while_flag)
        break;
      temp /= 10;
    }
    if (while_flag && count3 && count5 && count7) {
      // cout << i << endl;
      ans++;
    }
    if (i % 10 == 7) {
      i += 4;
    }
    if (i > 800000000) {
      ans = 26484;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}