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

#include <iostream>

using namespace std;

int n;

int prime[1000000];

int checked[1000000];

int primesum[1000000];

int result[30];

int datasets;

int main()

{

  prime[0] = 0;

  prime[1] = 0;

  primesum[0] = 0;

  primesum[1] = 0;

  for (int a = 2; a < 1000000; a++)

  {

    prime[a] = 1;
  }

  for (int a = 2; a < 1001; a++)

  {

    if (checked[a] == 0)

    {

      checked[a] = 1;

      for (int b = 2; b < a; b++)

      {

        if (a % b == 0)

        {

          prime[a] = 0;

          break;
        }
      }

      if (prime[a] == 1)

      {

        for (int c = 2 * a; c < 1000000; c += a)

        {

          checked[c] = 1;

          prime[c] = 0;
        }
      }
    }
  }

  for (int a = 2; a < 1000000; a++)

  {

    primesum[a] = primesum[a - 1] + prime[a];
  }

  while (cin >> n)

  {

    cout << primesum[n] << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int n;
int prime[1000000];
int checked[1000000];
int primesum[1000000];
int result[30];
int datasets;

int main() {
  prime[0] = 0;
  prime[1] = 0;
  prime[2] = 1;
  primesum[0] = 0;
  primesum[1] = 0;
  primesum[2] = 1;

  for (int a = 3; a < 1000000; a++) {
    if (checked[a] == 0) {
      prime[a] = 1;
      checked[a] = 1;
      for (int b = 2; b < a; b++) {
        if (a % b == 0) {
          prime[a] = 0;
          break;
        }
      }
      if (prime[a] == 1) {
        for (int c = 2 * a; c < 1000000; c += a) {
          checked[c] = 1;
        }
      }
    }
    primesum[a] = primesum[a - 1] + prime[a];
  }

  while (cin >> n) {
    cout << primesum[n] << endl;
  }

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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef int long long ll;

using namespace std;
/*int main(){

    ll n;
    while (cin>>n) {
        vector<ll> v;
        for(int i=0;i<n+1;i++){
            v.push_back(i);
        }
        ll b=v[v.size()-1];
        for(int i=2;i<=n;i++){
            ll j=2;
            while(i*j<=b){
                v[i*j]=0;
                j++;
            }
        }
        ll ans=0;
        for(int i=0;i<v.size();i++){
           // cout<<v[i]<<endl;
            if(v[i]!=0)ans++;
        }
        cout<<ans-1<<endl;
    }


    return 0;
}*/
int main() {

  ll n;
  while (cin >> n) {
    /* ll ans=0;
     for(int i=3;i<=n;i+=2){
         int flag=0;
     for(int j=3;j<=sqrt(i);j+=2){
         if(i%j==0){
             flag=1;
             break;
         }
     }
         if(flag==0){
             ans++;
         }
 }
     cout<<ans+1<<endl;*/

    vector<bool> IsPrime;
    if (n + 1 > IsPrime.size()) {
      IsPrime.resize(n + 1, true);
    }
    IsPrime[0] = false;
    IsPrime[1] = false;
    for (int i = 2; i <= sqrt(n); i++) {
      if (IsPrime[i])
        for (ll j = 2; i * j <= n; ++j) {
          IsPrime[i * j] = false;
        }
    }
    ll ans = 0;
    for (int i = 0; i < IsPrime.size(); i++) {
      if (IsPrime[i])
        ans++;
    }
    cout << ans << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef int long long ll;
using namespace std;
int main() {

  ll n;
  while (cin >> n) {
    ll ans = 0;
    for (int i = 3; i <= n; i += 2) {
      int flag = 0;
      for (int j = 3; j <= sqrt(i); j += 2) {
        if (i % j == 0) {
          flag = 1;
          break;
        }
      }
      if (flag == 0) {
        ans++;
      }
    }
    cout << ans + 1 << endl;
  }

  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  int head, fin;
  int temp;

  //	vector<int> isPrime;
  bool isPrime[1000000];

  while (cin >> n) {
    for (int i = 0; i < n + 1; i++) {
      //			isPrime.push_back(1);
      isPrime[i] = 1;
    }
    //		cout << "Corecced!" << endl;
    isPrime[0] = isPrime[1] = 0;
    temp = 0;

    for (;;) {
      // TõXgÌæªð©Â¯é
      for (head = temp + 1; head < n + 1; head++) {
        if (isPrime[head] == 1) {
          break;
        }
      }
      // æªðÜÜÈ¢{ÍSÄ¬
      for (int i = head; i * head < n + 1; i++) {
        isPrime[i * head] = 0;
      }
      // TõXgÌÅãÖ
      for (fin = n; fin > 0; fin--) {
        if (isPrime[fin] == 1) {
          break;
        }
      }
      //	printf("head:%d    fin:%d\\n",head,fin);

      if (fin <= head * head) {
        break;
      }
      temp = head;
    }

    int cont = 0;
    for (int i = 0; i < n + 1; i++) {
      if (isPrime[i] == 1) {
        cont++;
        //		cout << "+"<<i << endl;
      }
    }
    printf("%d\\n", cont);
  }
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n;
  int head, fin;
  int temp;

  //	vector<int> isPrime;
  int isPrime[100000];

  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      //			isPrime.push_back(1);
      isPrime[i] = 1;
    }
    //		cout << "Corecced!" << endl;
    isPrime[0] = isPrime[1] = 0;
    temp = 0;

    for (;;) {
      // TõXgÌæªð©Â¯é
      for (head = temp + 1; head < n; head++) {
        if (isPrime[head] == 1) {
          break;
        }
      }
      // æªðÜÜÈ¢{ÍSÄ¬
      for (int i = head; i * head < n; i++) {
        isPrime[i * head] = 0;
      }
      // TõXgÌÅãÖ
      for (fin = n; fin > 0; fin--) {
        if (isPrime[fin] == 1) {
          break;
        }
      }
      //			printf("head:%d    fin:%d\\n",head,fin);

      if (fin < head * head) {
        break;
      }
      temp = head;
    }

    int cont = 0;
    for (int i = 0; i < n; i++) {
      if (isPrime[i] == 1) {
        cont++;
      }
    }
    printf("%d\\n", cont);
  }
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <numeric>
#define MAX 1000000
using namespace std;

bool isPrime(int x) {
  if (x == 2) {
    return true;
  }

  if (x < 2 || x % 2 == 0) {
    return false;
  }
  for (int i = 3; i <= sqrt(x); i += 2) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  int n;
  bool a[MAX] = {};

  for (int i = 1; i < MAX; ++i) {
    if (isPrime(i)) {
      a[i] = true;
    }
  }
  /*
  for(int i = 1; i < MAX; ++i) {
        if(isPrime(i)) {
          cout << i << " ";
        }
  }
  */
  while (cin >> n) {
    cout << accumulate(&a[1], &a[n + 1], 0) << endl;
  }
  return 0;
}

/*-- primitive algorithm --*/
/*
bool isPrime(int n) {
  for(int i = 2; i < n; ++i) {
        if(n % i == 0) return false;
  }
  return true;
}
*/

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;
/*
bool isPrime(int n) {
  for(int i = 2; i < n; ++i) {
        if(n % i == 0) return false;
  }
  return true;
}
*/

bool isPrime(int x) {
  if (x == 2)
    return true;

  if (x < 2 || x % 2 == 0)
    return false;

  int i = 3;
  while (i <= sqrt(x)) {
    if (x % i == 0)
      return false;
    i += 2;
  }
  return true;
}

int main() {
  int n;
  while (cin >> n) {
    int cnt = 0;
    for (int j = 2; j <= n; ++j) {
      if (isPrime(j))
        cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

bool p[3000000];
vector<int> prime;

void init() {
  memset(p, 1, sizeof(p));
  p[0] = p[1] = false;
  for (int i = 2; i <= 1000000; i++) {
    if (!p[i])
      continue;
    for (long long j = 1LL * i * i; j <= 1000000; j += i)
      p[j] = false;
    prime.push_back(i);
  }
}

int CntPrime(int n) {
  // vector<int>::iterator it = lower_bound(prime.begin(), prime.end(), n);
  // if( *it > n) it--;
  // return (it - prime.begin() + 1);
  int res = 0;
  for (int i = 0; i < prime.size(); i++) {
    if (prime[i] <= n)
      res++;
    else
      break;
  }
  return res;
}

int main() {
  init();
  int n;
  while (cin >> n) {
    cout << CntPrime(n) << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

bool p[100000000];
vector<int> prime;

void init() {
  memset(p, 1, sizeof(p));
  p[0] = p[1] = false;
  for (int i = 2; i <= 1000000; i++) {
    if (!p[i])
      continue;
    for (long long j = 1LL * i * i; j <= 1000000; j += i)
      p[j] = false;
    prime.push_back(i);
  }
}

int CntPrime(int n) {
  vector<int>::iterator it = lower_bound(prime.begin(), prime.end(), n);
  if (*it > n)
    it--;
  return (it - prime.begin() + 1);
}

int main() {
  init();
  int n;
  while (cin >> n) {
    cout << CntPrime(n) << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
int N;
//??¨????????????????????????
bool is_prime[999999 + 1];
int E(const int N) {
  int cnt{};
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true; //?????????
  }
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      cnt++;
    }
  }
  return cnt;
}
int main() {
  while (cin >> N) {
    cout << E(N) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
int N;
//??¨????????????????????????
bool is_prime[10000 + 1];
vector<int> P;
int E(const int N) {
  int cnt{};
  for (int i = 0; i <= N; i++) {
    is_prime[i] = true; //?????????
  }
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      cnt++;
    }
  }
  return cnt;
}
int main() {
  while (cin >> N) {
    cout << E(N) << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
bool flg[1000000];
int main(void) {
  int n;
  int i, j;
  int cnt = 0;
  while (1) {
    cin >> n;
    if (cin.eof())
      break;
    fill(flg, flg + n + 1, 0);
    for (i = 2; i * i <= n; i++) {
      // cout<<"I="<<i<<endl;
      for (j = 2; i * j <= n; j++) {
        // cout<<"J="<<j<<endl;
        flg[i * j] = 1;
      }
    }
    cnt = 0;
    for (i = 2; i <= n; i++)
      if (flg[i] == 0)
        cnt++;
    cout << cnt << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
bool flg[1000000];
int main(void) {
  int n;
  int i, j;
  int cnt = 0;
  while (1) {
    cin >> n;
    if (cin.eof())
      break;
    fill(flg, flg + n + 1, 0);
    for (i = 2; i * i <= n; i++) {
      // cout<<"I="<<i<<endl;
      for (j = 2; j <= n; j++) {
        // cout<<"J="<<j<<endl;
        flg[i * j] = 1;
      }
    }
    cnt = 0;
    for (i = 2; i <= n; i++)
      if (flg[i] == 0)
        cnt++;
    cout << cnt << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>

int main() {
  int n;
  bool a;
  std::vector<int> prime;
  prime.emplace_back(2);
  for (int i = 3; i < 1000000; i += 2) {
    a = false;
    for (int j = 3; j <= std::sqrt(i); j += 2) {
      if (i % j == 0) {
        a = true;
      }
    }
    if (a == false) {
      prime.emplace_back(i);
    }
  }
  while (std::cin >> n) {
    int ans = 0;
    for (int i = 0; i < prime.size(); i++) {
      if (prime[i] <= n) {
        ans++;
      }
    }
    std::cout << ans << std::endl;
  }
}

Error: TLE

Fixed submission:


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
  int n;
  while (cin >> n) {
    vector<int> sos;
    sos.emplace_back(2);
    int s = 1;
    for (int j = 2; j <= n; j++) {
      for (int i = 0; i < sos.size(); i++) {
        if (j % sos[i] == 0) {
          break;
        }
        if (sos[i] > sqrt(j)) {
          sos.emplace_back(j);
          s++;
          break;
        }
      }
    }
    cout << s << endl;
  }
  return 0;
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <cstdio>
#include <iostream>
using namespace std;
#define OVER_SIX_DIGITS 1000000

int prime[OVER_SIX_DIGITS];

void make_prime(void) {
  for (int r = 0; r < OVER_SIX_DIGITS; r++)
    prime[r] = 1;
  prime[0] = prime[1] = 0;

  for (int r = 2; r < OVER_SIX_DIGITS; r++) {
    if (prime[r]) {
      for (int c = 2 * r; c < OVER_SIX_DIGITS; c += r)
        prime[c] = 0;
    }
  }
  // 累積和配列を作成
  for (int r = 1; r < OVER_SIX_DIGITS; r++)
    prime[r] += prime[r - 1];
}

int main(void) {
  int n;
  make_prime();
  while (cin >> n) {
    cout << prime[n] << endl;
  }
  return (0);
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <numeric>
using namespace std;

bool isPrime(int num) {
  if (num < 2)
    return (false);
  for (int r = 2; r * r <= num; r++) {
    if (num % r == 0)
      return (false);
  }
  return (true);
}

int main(void) {
  int num;

  while (cin >> num) {
    int prime[num + 1];
    memset(prime, -1, sizeof(prime));
    prime[0] = prime[1] = 0;
    int sum = 1;

    for (int r = 3; r <= num; r += 2) {
      if (prime[r] != -1)
        continue;
      if (prime[r] % 2 == 0)
        continue;
      if (isPrime(r)) {
        prime[r] = 1;
        sum++;
        for (int c = 2 * r; c <= num; c += r)
          prime[c] = 0;
      }
    }

    cout << sum << endl;
  }
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <vector>
#define N 999999

using namespace std;

int main() {
  int i, j, n, isFound, count;
  vector<int> data;

  data.push_back(2);
  data.push_back(3);
  for (i = 5; i <= N; i += 2) {
    for (j = 1, isFound = 0; data[j] <= sqrt(i); ++j) {
      if (i % data[j] == 0) {
        isFound = 1;
        break;
      }
    }
    if (isFound == 0)
      data.push_back(i);
  }

  while (cin >> n) {
    for (i = 0; i < data.size(); ++i) {
      if (n < data[i])
        break;
    }
    cout << i << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int main() {
  int n, i, j, isFound, count;

  while (cin >> n) {
    for (i = 3, count = 1; i <= n; i += 2) {
      for (j = 3, isFound = 0; j <= sqrt(i); j += 2) {
        if (i % j == 0) {
          isFound = 1;
          break;
        }
      }
      if (isFound == 0)
        count++;
    }
    cout << count << endl;
  }

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

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

using namespace std;

int main() {

  int n;
  int *k;

  while (cin >> n) {
    int counter = 0;
    k = (int *)malloc(sizeof(int) * n);
    if (k == NULL) {
      exit(0);
    }
    k[0] = 1;
    for (int i = 1; i < n; i++) {
      k[i] = 0;
    }

    for (int i = 1; i < n; i++) {
      if (k[i] == 0) {
        /*for (int j = 1; j < i; j++) {
                if (k[j] == 0) {
                        if ((i+1) % (j+1) == 0) {
                                k[i] = 1;
                                break;
                        }
                }
        }*/
        if (k[i] == 0) {
          for (int t = 2; t <= n / (i + 1); t++) {
            k[(i + 1) * t - 1] = 1;
          }
        }
      }
    }

    for (int i = 1; i < n; i++) {
      if (k[i] == 0) {
        counter++;
      }
    }

    cout << counter << endl;

    free(k);
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

int main() {

  int n;
  int *k;

  while (cin >> n) {
    int counter = 0;
    k = (int *)malloc(sizeof(int) * n);
    if (k == NULL) {
      exit(0);
    }
    k[0] = 1;
    for (int i = 1; i < n; i++) {
      k[i] = 0;
    }

    for (int i = 1; i < n; i++) {
      if (k[i] == 0) {
        for (int j = 1; j < i; j++) {
          if (k[j] == 0) {
            if ((i + 1) % (j + 1) == 0) {
              k[i] = 1;
              break;
            }
          }
        }
        if (k[i] == 0) {
          for (int t = 2; t < n / (i + 1); t++) {
            k[(i + 1) * t - 1] = 1;
          }
        }
      }
    }

    for (int i = 0; i < n; i++) {
      if (k[i] == 0) {
        counter++;
      }
    }

    cout << counter << endl;

    free(k);
  }

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <map>
#include <string>
using namespace std;

bool is_prime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return n != 1;
}

int main() {
  int n;
  int *table = new int[1000000];
  while (~scanf("%d", &n)) {

    fill((int *)table, (int *)table + n + 1, 1);
    table[0] = 0;
    table[1] = 0;

    for (int i = 2; i <= n; i++) {
      if (table[i]) {
        for (int j = i + i; j <= n; j += i) {
          table[j] = 0;
        }
      }
    }
    printf("%d\\n", count(table, table + n + 1, 1));
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <map>
#include <string>
using namespace std;

bool is_prime(int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return n != 1;
}

int main() {
  int n;
  int *table = new int[1000000];
  while (~scanf("%d", &n)) {

    fill((int *)table, (int *)table + n + 1, 1);
    table[0] = 0;
    table[1] = 0;

    for (int i = 2; i <= n; i++) {
      if (table[i] && !is_prime(i)) {
        for (int j = i; j <= n; j += i) {
          table[j] = 0;
        }
      }
    }
    printf("%d\\n", count(table, table + n + 1, 1));
  }
}
Problem p00009 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

vector<int> vec;

void makesosuu(void) {
  FOR(i, 2, 999999) {
    if (i == 2) {
      vec.pb(i);
    } else if (i % 2 != 0) {
      bool flag = true;
      int j = 3;
      while (j * j <= i) {
        if (i % j == 0) {
          flag = false;
          break;
        }
        j += 2;
      }
      if (flag)
        vec.pb(i);
    }
  }
  return;
}

int sosuu(int n) {
  int i = 0;
  while (vec[i] <= n && i < vec.size())
    ++i;

  return i;
}

int main() {
  int n;
  makesosuu();
  while (cin >> n) {
    cout << sosuu(n) << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <exception>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define LL long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

int sosuu(int n) {
  int ans = 0;

  FOR(i, 2, n) {
    if (i == 2) {
      ans++;
    } else if (i % 2 != 0) {
      bool flag = true;
      int j = 3;
      while (j * j <= i) {
        if (i % j == 0) {
          flag = false;
          break;
        }
        j += 2;
      }
      if (flag)
        ans++;
    }
  }
  return ans;
}

int main() {
  int n;
  while (cin >> n) {
    cout << sosuu(n) << endl;
  }
}
Problem p00010 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
using namespace std;
int main() {
  int a;
  scanf("%d", &a);
  for (; a > 0; a--) {
    double a1, a2, b1, b2, c1, c2, x1, y1, x2, y2, x3, y3;
    double x, y, r;
    scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
    a1 = 2 * (x2 - x1), b1 = 2 * (y2 - y1);
    c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
    a2 = 2 * (x3 - x1), b2 = 2 * (y3 - y1);
    c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
    x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
    y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
    r = hypot(x - x1, y - y1);
    printf("%.3lf %.3lf %.3lf\\n", x, y, r);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
using namespace std;
int main() {
  int a;
  scanf("%d", &a);
  for (;; a--) {
    double a1, a2, b1, b2, c1, c2, x1, y1, x2, y2, x3, y3;
    double x, y, r;
    scanf("%lf%lf%lf%lf%lf%lf", &x1, &y1, &x2, &y2, &x3, &y3);
    a1 = 2 * (x2 - x1), b1 = 2 * (y2 - y1);
    c1 = x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2;
    a2 = 2 * (x3 - x1), b2 = 2 * (y3 - y1);
    c2 = x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3;
    x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
    y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
    r = hypot(x - x1, y - y1);
    printf("%.3lf %.3lf %.3lf\\n", x, y, r);
  }
  return 0;
}