alexjercan/bugnet huggingface dataset:
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
bool has3(int x) {
  while (x) {
    if (x % 10 == 3)
      return true;
    x /= 10;
  }
  return false;
}
void call(int n) {
  for (int x = 1; x <= n; x++) {
    if (x % 3 == 0 || has3(x))
      cout << " " << x;
  }
  cout << endl;
}
int main() {
  int n;
  cin >> n;
  call(n);

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int H, W;
  while (1) {
    cin >> H >> W;
    if (H == 0 && W == 0)
      break;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if ((i + j) % 2 == 0) {
          cout << "#";
        } else {
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }

  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }
    do {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
    } while (x /= 10);
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }
    do {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
    } while (!(x /= 10));
  }
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
  int n;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
      continue;
    }

    int x = i;
    do {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
    } while (x /= 10);
  }

  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
  int n;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
      continue;
    }

    int x = i;
    do {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
    } while (x /= 10 != 0);
  }

  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      while (true) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }

        x = x / 10;
        if (x == 0) {
          break;
        }
      }
    }
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i < n + 1; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      while (true) {
        if (i % 10 == 3) {
          cout << " " << i;
          break;
        }

        i = i / 10;
        if (i == 0) {
          break;
        }
      }
    }
  }
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;

  int i = 0, x;
  while (++i <= n) {
    x = i;
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }
    while (x) {
      if (x % 10 == 3) {
        cout << " " << i;
        x = 0;
      }
      x /= 10;
    }
  }

  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;

  int i = 0, x;
  while (++i <= n) {
    x = i;
    if (i % 3 == 0) {
      cout << " " << i;
      continue;
    }
    while (x) {
      if (x % 10 == 3) {
        cout << " " << i;
        continue;
      }
      x /= 10;
    }
  }

  cout << endl;

  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, c, s, I;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    c = 0;
    s = 0;
    I = i;
    if (i % 3 == 0 && c == 0) {
      cout << " " << i;
      c++;
    }
    if (i % 10 == 3 && c == 0) {
      cout << " " << i;
      c++;
    }
    if (c == 0) {
      while (I / 10 != 0) {
        I /= 10;
        if (I == 3 || I % 10 == 3) {
          cout << " " << i;
          I = 0;
        }
      }
    }
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, c, t, s = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    c = 0;
    t = 10;
    if (i % 3 == 0 && c == 0) {
      cout << " " << i;
      c++;
    }
    if (i % 10 == 3 && c == 0) {
      cout << " " << i;
      c++;
    }
    while (i != 0) {
      i /= 10;
      s++;
    }
    for (int j = 0; j < s; j++) {
      if (i / t == 3 && c == 0) {
        cout << " " << i;
        c++;
      }
      t *= 10;
    }
  }
  cout << endl;
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdio.h>

int main(void) {

  int n;
  scanf("%d", &n);

  int i = 1;
  while (++i <= n) {
    int x = i;
    if (x % 3 == 0) {
      std::cout << " " << i;
      continue;
    }

    while (x) {
      if (x % 10 == 3) {
        std::cout << " " << i;
        break;
      }
      x /= 10;
    }
  }
  std::cout << std::endl;

  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
#include <stdio.h>

int main(void) {

  int n;
  scanf("%d", n);

  int i = 1;
  while (++i <= n) {
    int x = i;
    if (x % 3 == 0) {
      std::cout << " " << i;
      continue;
    }

    while (x) {
      if (x % 10 == 3) {
        std::cout << " " << i;
        break;
      }
      x /= 10;
    }
  }
  std::cout << std::endl;

  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main(void) {
  int i, n, x;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    x = i;
    if (x % 3 == 0) {
      printf(" %d", i);
    } else {
      while (x) {
        if (x % 10 == 3) {
          printf(" %d", i);
          break;
        }
        x = x / 10;
      }
    }
  }
  printf("\\n");
  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>
int main(void) {
  int i, n;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    if (i % 3 == 0)
      printf(" %d", i);
    if (i % 3 == 0)
      continue;
    while (1) {
      if (i % 10 == 3)
        printf(" %d", i);
      if (i % 10 == 3)
        break;
      i = i / 10;
      if (i < 10)
        break;
    }
  }
  printf("\\n");
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

void call(int n) {
  int i = 1;
CHECK_NUM:
  int x = i;
  if (x % 3 == 0) {
    cout << " " << i;
    goto END_CHECK_NUM;
  }
INCLUDE3:
  if (x % 10 == 3) {
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if (x)
    goto INCLUDE3;
END_CHECK_NUM:
  if (++i <= n)
    goto CHECK_NUM;

  cout << endl;
}

int main() {
  int n;
  cin >> n;
  call(n);
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int i = 1;
  int x = i;
  while (true) {
    if (x % 3 == 0) {
      cout << " " << i;
      if (!(++i <= n)) {
        break;
      }
    }
    if (x % 10 == 3) {
      cout << " " << i;
      if (!(++i <= n)) {
        break;
      }
    }
  }
  cout << endl;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    int x = i / 10;
    int y = i / 100;
    int z = i / 1000;
    if (i % 3 == 0)
      cout << " " << i;
    else if (i % 10 == 3)
      cout << " " << i;
    else if (x % 10 == 3)
      cout << " " << i;
    else if (y % 10 == 3)
      cout << " " << i;
    else if (z % 10 == 3)
      cout << " " << i;
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;

  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 10 == 3)
      cout << ' ' << i;
    else if ((i /= 10) % 10 == 3)
      cout << ' ' << i;
    else if ((i /= 100) % 10 == 3)
      cout << ' ' << i;
    else if ((i /= 1000) % 10 == 3)
      cout << ' ' << i;
  }
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      do {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x /= 10;
      } while (x);
    }
  }
  cout << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
using namespace std;

int main(void) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      do {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x /= 10;
      } while (1);
    }
  }
  cout << endl;
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
using namespace std;
int main() {
  int n, x;
  int i = 1;
  scanf("%d", &n);
  while (1) {
    x = i;
    if (x % 3 == 0) {
      printf(" %d", i);
    } else {
      while (x) {
        if (x % 10 == 3) {
          printf(" %d", i);
          break;
        }
        x /= 10;
      }
    }
    if (++i > n) {
      break;
    }
  }
  printf("\\n");
  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;
int main() {
  int n, x;
  int i = 1;
  scanf("%d", &n);
  while (1) {
    x = i;
    if (x % 3 == 0) {
      printf(" %d", i);
    } else {
      while (x) {
        if (x % 10 == 3) {
          printf(" %d", i);
          break;
        }
        x /= 10;
        if (++i > n) {
          break;
        }
      }
    }
  }
  printf("\\n");
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <cstdio>
int main() {
  int N;
  scanf("%d", &N);
  for (int n = 1; n <= N; n++) {
    if (n % 3 == 0) {
      printf(" %d", n);
    } else {
      int Q = n;
      int r;
      for (int j = 1;; j++) {
        r = Q % 10;
        Q = Q / 10;
        if (r == 3) {
          printf(" %d", n);
          break;
        }
        if (Q == 0) {
          break;
        }
      }
    }
  }
  printf("\\n");

  return 0;
}


Error: TLE

Fixed submission:

// 与えられた数nについて、1~nまでの数の中で、3の倍数と3の数字が含まれる数を昇順で出力する

#include <cstdio>
int main() {
  int N;
  scanf("%d", &N);
  for (int n = 1; n <= N; n++) {
    if (n % 3 == 0) {
      printf(" %d", n);
    } else {
      int Q = 1;
      int r;
      for (int j = 1;; j++) {
        Q = n / 10;
        r = n % 10;
        if (r == 3) {
          printf(" %d", n);
          break;
        }
        if (Q == 0) {
          break;
        }
      }
    }
  }
  printf("\\n");

  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int n;
int main() {
  while (cin >> n) {
    for (int i = 1; i <= n; i++) {
      bool judge = false;
      if (i % 3 == 0)
        judge = true;
      int j = i;
      while (j > 0 && !judge) {
        if (j % 10 == 3)
          judge = true;
        j /= 10;
      }
      if (judge)
        cout << " " << i;
    }
    cout << endl;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int n;
int main() {
  while (cin >> n) {
    for (int i = 1; i <= n; i++) {
      bool judge = false;
      if (i % 3 == 0)
        judge = true;
      while (i > 0 && !judge) {
        if (i % 10 == 3)
          judge = true;
        i /= 10;
      }
      if (judge)
        cout << " " << i;
    }
    cout << endl;
  }
}
Problem p02406 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main(void) {
  int a, b;
  cin >> a;

  for (int i = 1; i <= a; i++) {
    b = i;
    if (i % 3 == 0)
      cout << " " << i;
    else if (b % 10 == 3)
      cout << " " << i;
    else if (b / 10 % 10 == 3)
      cout << " " << i;
    else if (b / 100 % 10 == 3)
      cout << " " << i;
    else if (b / 1000 % 10 == 3)
      cout << " " << i;
  }
  cout << endl;
  return 0;
}


Error: -8

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  // Your code here!
  int a, b;
  cin >> a;

  for (int i = 1; i <= a; i++) {
    b = i;
    if (i % 3 == 0)
      cout << " " << i;
    while (b / 0) {
      b /= 10;
      cout << b;
    }
    if (b % 10 == 3 && i > 3)
      cout << " " << i;
  }

  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

void call(int n) {
  int i = 1;
  do {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }
    do {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    } while (x);
  } while (++i <= n);
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  call(n);
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>

using namespace std;

void call(int n) {
  for (int i = 1; i <= n; i++) {
    int x = i;
    // CHECK_NUM
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }
    // INCLUDE3
    while (x) {
      if (x % 10 == 3) {
        cout << " " << i;
        continue;
      }
      x /= 10;
    }
  }
}

int main() {
  int n;
  cin >> n;
  call(n);
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;

  cin >> n;

  for (int i = 1; i <= n; i++) {
    int x = i;

    if (x % 3 == 0) {
      cout << " " << i;
      x = 0;
    }

    while (x) {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    }
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  int i = 1;
  bool check;

  cin >> n;

  while (++i <= n) {
    check = false;
    int x = i;

    if (x % 3 == 0) {
      cout << " " << i;
      check = true;
    }

    while (x) {
      if (x % 10 == 3) {
        cout << " " << i;
        check = true;
      }
      if (!check) {
        x /= 10;
      }
      check = false;
    }
  }
  cout << endl;

  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

void include3(int x, int i) {
  if (x % 10 == 3) {
    printf(" %d", i);
    return;
  }
  x /= 10;
  if (x)
    return include3(x, i);
  return;
}

int main() {
  int n;
  int i;
  int x;

  scanf("%d", &n);

  for (i = 1; i <= n; i++) {
    x = i;
    if (x % 3 == 0) {
      printf(" %d", i);
      continue;
    }
    include3(x, i);
  }
  printf("\\n");

  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

void include3(int x, int i) {
  if (x % 10 == 3) {
    printf(" %d", i);
    return;
  }
  x /= 10;
  if (x)
    return include3(x, i);
  return;
}

int main() {
  int n;
  int i;
  int x;

  scanf("%d", &n);
  while (n >= 3 && n <= 10000) {
    for (i = 1; i <= n; i++) {
      printf("%d", i);
      x = i;
      if (x % 3 == 0) {
        printf(" %d", i);
        break;
      }
      include3(x, i);
    }
    printf("\\n");
    scanf("%d", &n);
  }

  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; ++i <= n;) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      while (1) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x /= 10;
        if (x < 1)
          break;
      }
    }
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i++ <= n;) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    } else {
      if (x % 10 == 3) {
        cout << " " << i;
      } else {
        while (1) {
          x /= 10;
          if (x && x % 10 == 3) {
            cout << " " << i;
            break;
          }
        }
      }
    }
  }
  cout << endl;
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;

  for (int i = 1; i <= n; ++i) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }
    if (x % 10 == 3) {
      cout << " " << i;
      continue;
    }
    x /= 10;
    for (;;) {
      if (x) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
        x /= 10;
      } else {
        break;
      }
    }
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, i, x;
  while (1) {
    cin >> n;
    /*if(W == 0 & H == 0)
            break;*/

    for (i = 0; i <= n; i++) {
      if (i % 3 == 0) {
        cout << " " << i;
      } else if (i % 10 == 3) {
        cout << " " << i;
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int i = 1;
  for (int i = 1; i <= n; i++) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }
    do {
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    } while (x);
  }
  cout << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int i = 1;
  for (int i = 1; i <= n; i++) {
    int x = i;
    if (x % 3 == 0) {
      cout << " " << i;
      continue;
    }
    do {
      if (x % 10 == 3) {
        cout << " " << i;
        continue;
      }
      x /= 10;
    } while (x);
  }
  cout << endl;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iomanip>
#include <iostream>
using namespace std;
const int M = 100000;
const double pi = 3.141592653589;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      int x = i;
      while ((x % 10) != 3 && x != 0) {
        x /= 10;
      }
      if (x != 0) {
        cout << " " << i;
      }
    }
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iomanip>
#include <iostream>
using namespace std;
const int M = 100000;
const double pi = 3.141592653589;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      int x = i;
      while ((x % 10) != 3 || x != 0) {
        x /= 10;
      }
      if (x != 0) {
        cout << " " << i;
      }
    }
  }
  cout << endl;

  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 10 == 3) {
      cout << " " << i;
      continue;
    }
    int x = i;
    while (x) {
      x /= 10;
      if (x % 10 == 3) {
        cout << " " << i;
        break;
      }
    }
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0 || i % 10 == 3) {
      cout << " " << i;
      continue;
    }
    while (int x = i) {
      x /= 10;
      if (x % 10 == 3)
        cout << " " << i;
    }
  }
  cout << endl;
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iomanip>
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x = i;
    if (x % 3 == 0) {
      cout << ' ' << i;
    } else {
      while (x) {
        if (x % 10 == 3) {
          cout << ' ' << i;
          break;
        }
        x /= 10;
      }
    }
  }
  cout << endl;
}

Error: TLE

Fixed submission:

#include <iomanip>
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x = i;
    if (x % 3 == 0) {
      cout << ' ' << i;
    } else {
      while (x) {
        if (x / 10) {
          if (x % 10 == 3) {
            cout << ' ' << i;
          }
          x /= 10;
        }
      }
    }
  }
  cout << endl;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
    } else {
      for (int x = i; x != 0; x /= 10) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }
      }
    }
  }
  cout << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x = i;
    while (x > 0) {
      if (x % 3 == 0 || x % 10 == 3) {
        cout << " " << i;
      } else {
        x /= 10;
      }
    }
  }
  cout << endl;

  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, m;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    m = i;
    if (m % 3 == 0) {
      cout << " " << i;
      continue;
    }
    while (1) {
      if (m == 0)
        break;
      if (m % 10 == 3) {
        cout << " " << i;
        break;
      }
      m /= 10;
      if (m)
        continue;
    }
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i <= n; i++) {
    if (i % 3 == 0) {
      cout << " " << i;
      continue;
    }
    i /= 10;
    if (i) {
      if (i % 10 == 3) {
        cout << " " << i;
        continue;
      }
    }
  }
  cout << endl;
  return 0;
}
Problem p02406 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n, x, i = 1;
  cin >> n;
  while (i <= n) {
    x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    }

    else {
      while (1) {
        if (x % 10 == 3) {
          cout << " " << i;
          break;
        }

        x /= 10;
        if (x == 0) {
          break;
        }
      }
    }
    ++i;
  }
  cout << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int x, i = 1, n;
  cin >> n;
  while (++i <= n) {
    x = i;
    if (x % 3 == 0) {
      cout << " " << i;
    }
    while (1) {
      if (x % 10 == 3) {
        cout << " " << i;
      }
      x /= 10;
      if (x != 0) {
        break;
      }
    }
  }
  cout << endl;
  return 0;
}