alexjercan/bugnet huggingface dataset:
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <vector>

using namespace std;

vector<bool> prime(10000001, 1);

signed main() {
  prime[0] = prime[1] = 0;
  for (int i = 2; i * i < 10000001; i++) {
    if (prime[i]) {
      for (int j = 1; i * (j + 1) < 10000001; j++) {
        prime[i * (j + 1)] = 0;
      }
    }
  }

  int n;
  while (scanf("%d\\n", &n) != EOF) {
    if (n == 0)
      break;
    int sum = 0, cnt = 0;
    for (int i = 0; cnt < n; i++) {
      if (prime[i]) {
        sum += i;
        cnt++;
      }
    }
    printf("%d\\n", sum);
  }
  return 0;
}


Error: 0

Fixed submission:

#include <cstdio>
#include <vector>

using namespace std;

vector<bool> prime(10001, 1);

signed main() {
  prime[0] = prime[1] = 0;
  for (int i = 2; i * i < 10001; i++) {
    if (prime[i]) {
      for (int j = 1; i * (j + 1) < 10001; j++) {
        prime[i * (j + 1)] = 0;
      }
    }
  }

  int n;
  while (scanf("%d\\n", &n) != EOF) {
    if (n == 0)
      break;
    int sum = 0, cnt = 0;
    for (int i = 0; cnt < n; i++) {
      if (prime[i]) {
        sum += i;
        cnt++;
      }
    }
    printf("%d\\n", sum);
  }
  return 0;
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  bool prime[10000000];
  fill(prime, prime + 1000000, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i < 1000000; i++) {
    for (int j = 2; j * i < 1000000; j++) {
      if (!prime[i * j])
        continue;
      prime[i * j] = false;
    }
  }

  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int t = 0, sum = 0;
    while (n > 0) {
      if (!prime[++t])
        continue;

      n--;
      sum += t;
    }
    cout << sum << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  bool prime[10001];
  fill(prime, prime + 10001, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i < 10001; i++) {
    for (int j = 2; j * i < 10001; j++) {
      if (!prime[i * j])
        continue;
      prime[i * j] = false;
    }
  }

  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int t = 0, sum = 0;
    while (n > 0) {
      if (!prime[++t])
        continue;

      n--;
      sum += t;
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  bool prime[1000000];
  fill(prime, prime + 1000000, true);
  prime[0] = prime[1] = false;
  for (int i = 2; i * i < 1000000; i++) {
    for (int j = 2; j * i < 1000000; j++) {
      if (!prime[i * j])
        continue;
      prime[i * j] = false;
    }
  }

  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int t = 0, sum = 0;
    while (n > 0) {
      if (!prime[++t])
        continue;

      n--;
      sum += t;
    }
    cout << sum << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include "bits/stdc++.h"
using namespace std;

int main() {
  int n;
  vector<int> vi;
  int data[10005] = {0};
  for (int i = 0; i < 10005; ++i) {
    data[i] = i;
  }
  for (int i = 2; i <= sqrt(10005); ++i) {
    for (int j = i * 2; j <= 10005; j = j + i) {
      data[j] = 0;
    }
  }
  for (int i = 2; i <= 10005; ++i) {
    if (data[i])
      vi.push_back(data[i]);
  }

  while (cin >> n) {
    if (!n)
      break;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
      sum += vi[i];
    }
    cout << sum << endl;
  }
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int prime[120001], num, cou = 0, ans = 0;
  for (int i = 2; i <= 120000; i++)
    prime[i] = 0;
  for (int i = 2; i <= (int)sqrt(120000); i++) {
    for (int j = 2; j * i <= 120000; j++)
      prime[i * j] = 1;
  }
  while (cin >> num && num != 0) {
    for (int i = 2; cou < num; i++) {
      if (prime[i] == 0) {
        ans += i;
        cou++;
      }
    }
    cout << ans << endl;
    ans = 0;
    cou = 0;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int prime[40001], num, cou = 0, ans = 0;
  for (int i = 2; i <= 40000; i++)
    prime[i] = 0;
  for (int i = 2; i <= (int)sqrt(40000); i++) {
    for (int j = 2; j * i <= 40000; j++)
      prime[i * j] = 1;
  }
  while (cin >> num && num != 0) {
    for (int i = 2; cou < num; i++) {
      if (prime[i] == 0) {
        ans += i;
        cou++;
      }
    }
    cout << ans << endl;
    ans = 0;
    cou = 0;
  }
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  const int NUM = 1e6;
  bool prime[NUM];
  for (int i = 2; i < NUM; i++)
    prime[i] = true;
  for (int i = 2; i * i < NUM; i++)
    for (int k = 2; i * k < NUM; k++)
      prime[i * k] = false;
  int n, c;
  while (cin >> n) {
    if (!n)
      break;
    c = 0;
    for (int i = 2, k = 0; k < n; i++)
      if (prime[i])
        c += i, k++;
    cout << c << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  const int NUM = 10000;
  bool prime[NUM];
  for (int i = 2; i < NUM; i++)
    prime[i] = true;
  for (int i = 2; i * i < NUM; i++)
    for (int k = 2; i * k < NUM; k++)
      prime[i * k] = false;
  int n, c;
  while (cin >> n) {
    if (!n)
      break;
    c = 0;
    for (int i = 2, k = 0; k < n; i++)
      if (prime[i])
        c += i, k++;
    cout << c << endl;
  }
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
unsigned long long a[100000], b[200000], c, n;
using namespace std;
int main() {
  for (int i = 2; i < 200000; i++)
    for (int j = i * 2; j < 200000; j += i)
      b[j]++;
  for (int i = 2; i < 200000; i++)
    if (!b[i]) {
      a[c + 1] += i + a[c];
      c++;
    }
  while (cin >> n, n)
    cout << a[n] << endl;
}

Error: 0

Fixed submission:

#include <iostream>
unsigned long long a[10001], b[200000], c, n;
using namespace std;
int main() {
  for (int i = 2; i < 200000; i++)
    for (int j = i * 2; j < 200000; j += i)
      b[j]++;
  for (int i = 2; i < 200000; i++)
    if (!b[i]) {
      a[c + 1] += i + a[c];
      c++;
    }
  while (cin >> n, n)
    cout << a[n] << endl;
}
Problem p00053 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

void solve(int ans[10001]) {
  bool flag = true;
  int count = 0;
  int all = 0;
  for (int i = 2;; i++) {
    for (int j = 2; j < i / 2 + 1; j++) {
      if (i % j == 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      count++;
      all += i;
      ans[count] = all;
      if (count == 10000) {
        break;
      }
    } else {
      flag = true;
    }
  }
}

int main() {
  int ans[10001];
  solve(ans);
  int num;
  while (cin >> num, num) {
    cout << ans[num] << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int solve(int num) {
  bool flag = true;
  int count = 0;
  int all = 0;
  for (int i = 2;; i++) {
    for (int j = 2; j < i / 2 + 1; j++) {
      if (i % j == 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      count++;
      all += i;
    } else {
      flag = true;
    }
    if (count == num) {
      return all;
    }
  }
}

int main() {
  int num;
  while (cin >> num, num) {
    cout << solve(num) << endl;
  }
  return 0;
}
Problem p00053 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

constexpr int MAX = 10000;

bool isPrime(int n);

int main() {
  vector<int> prime_list;
  prime_list.reserve(MAX);

  int p = 2;
  while (prime_list.size() != MAX) {
    if (isPrime(p)) {
      prime_list.push_back(p);
    }
    p++;
  }

  int n;
  while (cin >> n && n != 0) {
    int sum = 0;
    for (auto i = 0; i < n; i++) {
      sum += prime_list.at(i);
    }
    cout << sum << endl;
  }

  return 0;
}

bool isPrime(int n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      return false;
    }
  }

  return true;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

typedef pair<int, bool> elem;

int main() {
  vector<elem> is_prime(10000 + 1);

  is_prime.at(0) = elem(0, false);
  is_prime.at(1) = elem(1, false);

  for (size_t i = 2; i < is_prime.size(); i++) {
    is_prime.at(i) = elem(i, true);
  }

  for (size_t i = 2; i < is_prime.size() / 2; i++) {
    if (is_prime.at(i).second) {
      for (size_t j = i * 2; j < is_prime.size(); j += i) {
        is_prime.at(j).second = false;
      }
    }
  }

  int n;
  while (cin >> n && n != 0) {
    int sum = 0;

    size_t i = 2;
    while (n--) {
      while (!is_prime.at(i).second) {
        i++;
      }
      sum += is_prime.at(i).first;
      i++;
    }

    cout << sum << endl;
  }

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

#include <cmath>
#include <iostream>

using namespace std;

int main() {

  int n;

  int not_prime[104730];
  int s;

  int count;

  not_prime[0] = not_prime[1] = 1;

  for (int i = 2; i <= 104730; i++)
    not_prime[i] = 0;

  for (int i = 2; i <= sqrt(104730); i++) {

    if (not_prime[i] == 0) {

      for (int j = 2 * i; j <= 104730; j += i) {

        not_prime[j] = 1;
      }
    }
  }

  // for(int i=2;i<104730;i++) if(not_prime[i]==0) cout << i << endl;

  while (cin >> n) {

    if (n == 0)
      break;

    s = 0;
    count = 0;

    for (int i = 2; count < n; i++) {

      if (not_prime[i] == 0) {

        s += i;
        count++;
      }
    }

    cout << s << endl;
  }

  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>

int main(void) {

  int n;

  int is_prime[200001];
  long prime[10001];
  int s;

  int i, j, div;
  int p = 0;

  is_prime[0] = 0;
  is_prime[1] = 0;

  for (i = 2; i <= 200000; i++)
    is_prime[i] = 1;

  for (i = 2; i <= 200000; i++) {

    if (is_prime[i] == 1) {

      prime[p] = i;

      p++;

      for (j = 2 * i; j <= 200000; j += i)
        is_prime[j] = 0;
    }
  }

  // for(j=0;j<10000;j++) printf("%d ",prime[j]);

  while (1) {

    scanf("%d", &n);

    if (n == 0)
      break;

    s = 0;

    for (i = 0; i < n; i++)
      s += prime[i];

    printf("%d\\n", s);
  }

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

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <complex>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

typedef complex<double> P;

#define X real()
#define Y imag()
typedef int kz;

kz gcd(kz a, kz b) {
  if (b == 0)
    return a;
  else
    gcd(b, a % b);
}

int main() {
  int mod = 1000000007;
  int m = 70099;
  int a, b, n;
  while (scanf("%d %d %d", &a, &b, &n) != EOF) {
    int ans = 0;
    while (n > 0) {
      a = a % b * 10;
      ans += a / b;
      n -= 1;
    }
    printf("%d\\n", ans);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <complex>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

typedef complex<double> P;

#define X real()
#define Y imag()
typedef int kz;

kz gcd(kz a, kz b) {
  if (b == 0)
    return a;
  else
    gcd(b, a % b);
}

int main() {
  int mod = 1000000007;
  int m = 70099;
  int a, b, n;
  while (scanf("%d %d %d", &a, &b, &n)) {
    int ans = 0, f = 0;
    while (n > 0) {
      if (a % b != 0)
        f = 1;
      a *= 10;
      a %= m;
      if (f == 1) {
        ans += a / b % 10;
        n -= 1;
      }
    }
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00054 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, l, n) for (int i = l; i < n; i++)
#define rer(i, l, n) for (int i = l; i <= n; i++)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main() {
  int a, b;
  int n;
  while (cin >> a >> b >> n) {
    int s = 0;
    if (a >= b) {
      a %= b;
    }
    rep(i, 1, n + 1) {
      a *= 10;
      // o(" "<<a);
      if (a / b == 0)
        continue;
      else {
        s += a / b;
        a %= b;
      }
    }
    o(s);
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, l, n) for (int i = l; i < n; i++)
#define rer(i, l, n) for (int i = l; i <= n; i++)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define pb(a) push_back(a)
#define mk(a, b) make_pair(a, b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main() {
  int c = 0;
  double a, b, sum = 0.0;
  double x[21] = {}, y[21] = {};
  while (scanf("%lf,%lf", &a, &b) != EOF) {
    // if(a==-1) break;
    if (c == 0) {
      x[c] = a;
      y[c] = b;
    } else {
      x[c] = a - x[0];
      y[c] = b - y[0];
    }
    c++;
  }
  rep(i, 1, c - 1) { sum += 0.5 * abs(x[i] * y[i + 1] - x[i + 1] * y[i]); }
  printf("%.10lf\\n", sum);
}
/*
double dist(double x1,double y1,double x2,double y2){
        return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

double solve(double x1,double y1,double x2,double y2,double x3,double y3){
        double a,b,c,z,s;
        a=dist(x1,y1,x2,y2);
        b=dist(x2,y2,x3,y3);
        c=dist(x3,y3,x1,y3);
        z=(a+b+c)*0.5;
        s=sqrt(z*(z-a)*(z-b)*(z-c));
        return s;
}

int main(){
        char c;
        double x1,y1,x2,y2,x3,y3,sum=0;
        cin>>x1>>c>>y1>>x2>>c>>y2;
        //scanf("%lf,%lf%c%lf,%lf",&x1,&y1,&c,&x2,&y2);
        while(scanf("%lf,%lf",&x3,&y3)!=EOF){
                sum+=solve(x1,y1,x2,y2,x3,y3);
                x2=x3; y2=y3;
                o(" "<<sum);
        }
        printf("%.10lf",sum);
}*/
/*
typedef complex<double> xy_t;

//??????????¬?????????¢????????????
double cross_product(xy_t a,xy_t b){
        return (conj(a)*b).imag();
}

xy_t P[110];

int main(){
        int n=0;
        double x,y;
        while(~scanf("%lf,%lf",&x,&y)){
                P[n++]=xy_t(x,y);
        }
        double sum=0.0;
        rep(i,0,n-2){
                xy_t a=P[0],b=P[i+1],c=P[i+2];
                sum+=0.5*cross_product(b-a,c-a);
        }
        printf("%.6lf\\n",abs(sum));
}*/
Problem p00054 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int a, b, n;
  int total;
  int c;
  while (cin >> a >> b >> n) {
    total = 0;
    c = a % b * 10;
    for (int i = 0; i < n; i++) {
      total += c / b;
      c = c % b * 10;
    }
    cout << total << endl;
  }
}

Error: -11

Fixed submission:

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

int main() {
  double a, b;
  int n;
  char s[20];
  int cnt;
  int total = 0;
  while (cin >> a >> b >> n) {
    cnt = 0;
    a /= b;
    sprintf(s, "%lf", a);
    while (1) {
      total = 0;
      if (s[cnt] == '.') {
        for (int i = cnt + 1; i < i + n; i++)
          total += (s[i] - '0');
        break;
      }
      cnt++;
    }
    cout << total << endl;
  }
}
Problem p00054 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {

  unsigned long long a, b;
  int n;
  while (cin >> a >> b >> n) {
    unsigned long long sum = 0;
    for (int i = 0; i < n; i++) {
      a = a % b;
      a *= 10;
      sum += a / b;
    }
    cout << sum << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <cassert>
#include <iostream>

using namespace std;

int main() {

  unsigned long long a, b;
  int n;
  while (cin >> a >> b >> n) {
    unsigned long long sum = 0;
    assert(n < 20);
    for (int i = 0; i < n; i++) {
      a *= 10;
      sum += (a / b) % 10;
    }
    cout << sum << endl;
  }

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define INF 100000000
#define pb push_back
#define fi first
#define sec second
#define SS stringstream
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

int a, b, n;

int main() {
  while (cin >> a >> b >> n) {
    int s = 0;
    a = a % b;
    for (int i = 1; i <= n; i++) {
      a = a * 10;
      s += a / b;
      a = a % b;
    }
    cout << s << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define INF 100000000
#define pb push_back
#define fi first
#define sec second
#define SS stringstream
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

int a, b, n;
double af, bf;

int main() {
  while (scanf("%d%d%d", &a, &b, &n)) {
    int ans = 0;
    double x;
    af = (double)a;
    bf = (double)b;
    x = af / bf;
    for (int i = 1; i <= n; i++) {
      ans += ((int)(x * pow(10, i))) % 10;
    }
    cout << ans << endl;
  }
}
Problem p00054 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = (x); i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)

#define ALL(a) (a).begin(), (a).end()
#define SORT(c) sort((c).begin(), (c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

using namespace std;

//================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int A, B, N, ans;
  while (cin >> A >> B >> N) {
    ans = 0;
    REP(i, N) {
      A *= 10;
      ans += (A / B) % 10;
      A %= B;
    }
    cout << ans << "\\n";
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = (x); i < (n); i++)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)

#define ALL(a) (a).begin(), (a).end()
#define SORT(c) sort((c).begin(), (c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

using namespace std;

//================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  double A, B, N, ans;
  while (cin >> A >> B >> N) {

    ans = A / B;
    string str = to_string(ans);
    reverse(ALL(str));

    int strSize = str.size();

    REP(i, strSize) {
      if (str[i] == '.') {
        str.replace(i, (strSize - i), "");
        break;
      }
    }
    strSize = str.size();
    str = str.substr(strSize - N);
    reverse(ALL(str));

    ans = 0;
    strSize = str.size();
    REP(i, strSize) { ans += (int)(str[i] - '0'); }

    cout << floor(ans) << "\\n";
  }
  return 0;
}
Problem p00054 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int func(int a, int b, int n) {
  if (n == 0) {
    return 0;
  }
  int u = 10 * a;

  return (u / b + func(u % b, b, n - 1));
}

int main() {
  int n, a, b;

  while (cin >> a >> b >> n) {
    a %= b;
    cout << func(a, b, n) << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int func(int a, int b, int n) {
  if (n == 0) {
    return 0;
  }
  int u = 10 * a;

  return (u / b + func(u % b, b, n - 1));
}

int main() {
  int n, a, b;

  while (cin >> a >> b >> n) {
    while (a >= b) {
      a /= b;
    }
    cout << func(a, b, n) << endl;
  }

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

#include <cstdio>

using namespace std;

int main() {

  int a, b, n;
  int ab, ab2;
  int c;

  while (scanf("%d %d %d", &a, &b, &n) != EOF) {
    c = ab = ab2 = 0;

    if (a / b != 0) {
      a %= b;
    }

    for (int i = 0; i < n; i++) {
      if (a / b == 0) {
        a *= 10;
      }
      ab = a / b;
      ab2 = a % b;

      c += ab;
      a = ab2;
    }

    printf("%d\\n", c);
  }
}

Error: TLE

Fixed submission:

#include <cstdio>

using namespace std;

int main() {

  double a, b, n;
  double ab, cc;
  int c;

  while (scanf("%lf %lf %lf", &a, &b, &n) != EOF) {
    c = 0;
    ab = a / b;
    while (ab > 9)
      ab /= 10;
    for (int i = 0; i < n; i++) {
      cc = ab;
      for (int j = 0; j <= i; j++) {
        cc *= 10;
      }
      while (cc > 9)
        cc -= 10;
      c += cc;
    }

    printf("%d\\n", c);
  }
}
Problem p00054 (C++) — buggy submission, verdict: Runtime Error

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

int solve(int a, int b, int n) {
  int ans = 0;
  a %= b;
  a *= 10;
  for (int i = 0; i < n; i++) {
    ans += a / b;
    a %= b;
    a *= 10;
  }
  return ans;
}

int main() {
  int a, b, c;
  while (cin >> a >> b >> c) {
    cout << solve(a, b, c) << endl;
  }
}

Error: WA

Fixed submission:

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

int main() {
  int sell = 0, num = 0;
  int a, b, count = 0;
  while (scanf("%d,%d", &a, &b) != EOF) {
    count++;
    sell += a;
    num += b;
  }
  cout << sell << endl;
  cout << num / b << endl;
}
Problem p00054 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

int main() {
  int a, b;
  int n;

  while (cin >> a >> b >> n) {
    int s = 0;
    for (int i = 0; i < n; i++) {
      a *= 10;
      s += a / b % 10;
      a %= b;
    }
    cout << s << endl;
  }

  return (0);
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int a, b;
  int n;

  while (cin >> a >> b >> n, a != EOF) {
    int s[n];
    int sum = 0;
    for (int i = 1; i <= n; i++) {
      int power = pow(10, i);
      s[i] = (float)a / (float)b * power;
      s[i] %= 10;
      sum += s[i];
    }
    cout << sum << endl;
  }

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) for (int i = 0; i < a; i++)
int main(void) {
  int a, b, n;
  while (cin >> a >> b >> n) {

    unsigned long long int res = 0;
    /*
    double dis = 1.0*a/b*10;
    rep(i,n){
      res += (int)dis%10;
      //cout<<dis<<endl;
      dis *= 10;
    }
    */
    /* make first
    unsigned long long int sum = (int)(a*1.0/b * pow(10,n));
    cout<<pow(10,n)<<endl;;
    cout<<sum<<endl;
    rep(i,n){
      res += sum % 10;
      sum /= 10;
    }
    */

    ///* sum each line

    loop(i, 1, n + 1) {
      res += (unsigned long long)(a * 1.0 / b * pow(10, i)) % 10;
    }

    cout << res << endl;
    ;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a) for (int i = 0; i < a; i++)
int main(void) {
  int a, b, n;
  while (cin >> a >> b >> n, a + b + n) {
    int res = 0;
    double now = (double)(1.0 * a / b);
    int po = 1;
    rep(i, n) {

      res += (int)(now * 10) % 10 / 1;
      now *= 10;
    }
    cout << res << endl;
  }
}