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

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

using namespace std;
bool IsPrime[1005000];
vector<int> Prime;

void PrimeCalc() {
  for (int i = 0; i < 1005000; ++i) {
    IsPrime[i] = true;
  }
  for (int i = 2; i < 1005000; ++i) {
    if (IsPrime[i]) {
      Prime.push_back(i);
      for (int j = i * 2; j < 1005000; j += i) {
        IsPrime[j] = false;
      }
    }
  }
}

int func(int a) {
  set<int> Set;
  for (int i = 0; Prime[i] <= a; ++i) {
    if (a % Prime[i] == 0) {
      Set.insert(Prime[i]);
    }
  }
  int sum = 0;
  set<int>::iterator It;
  for (It = Set.begin(); It != Set.end(); ++It) {
    sum -= *It;
  }
  --It;
  sum += *It * 2;
  return (sum);
}

void solve() {
  PrimeCalc();
  int a, b;
  while (cin >> a >> b, a || b) {
    int A = func(a);
    int B = func(b);
    A < B ? cout << "b" : cout << "a";
    cout << endl;
  }
}

int main() {
  solve();
  return (0);
}

Error: 0

Fixed submission:

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

using namespace std;
bool IsPrime[1000001];
vector<int> Prime;

void PrimeCalc() {
  fill(IsPrime, IsPrime + 1000001, true);
  for (int i = 2; i < 1000001; ++i) {
    if (IsPrime[i]) {
      Prime.push_back(i);
      for (int j = i * 2; j < 1000001; j += i) {
        IsPrime[j] = false;
      }
    }
  }
}

int func(int a) {
  set<int> Set;
  for (int i = 0; Prime[i] <= a; ++i) {
    if (a % Prime[i] == 0) {
      Set.insert(Prime[i]);
    }
  }
  int sum = 0;
  set<int>::iterator It;
  for (It = Set.begin(); It != Set.end(); ++It) {
    sum -= *It;
  }
  --It;
  sum += *It * 2;
  return (sum);
}

void solve() {
  PrimeCalc();
  int a, b;
  while (cin >> a >> b, a || b) {
    int A = func(a);
    int B = func(b);
    A < B ? cout << "b" : cout << "a";
    cout << endl;
  }
}

int main() {
  solve();
  return (0);
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
const int LMAX = 2010;
int main() {
  int a, b;
  while (cin >> a >> b, a + b) {
    vi amr(b + 1);
    amr[a] = 1;
    int co = 1;
    while (1) {
      co++;
      a *= 10;
      a %= b;
      if (amr[a]) {
        int t = co - amr[a];
        cout << co - t - 1 << " " << t << endl;
        goto end;
      }
      if (a == 0) {
        cout << co - 1 << " 0" << endl;
        break;
      }
      amr.pb(a);
      amr[a] = co;
    }
  end:;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
const int LMAX = 2010;
int main() {
  int a, b;
  while (cin >> a >> b, a + b) {
    vi amr(1, a);
    while (1) {
      a *= 10;
      a %= b;
      rep(i, amr.size()) if (a == amr[i]) {
        int t = amr.size() - i;
        cout << amr.size() - t << " " << t << endl;
        goto end;
      }
      if (a == 0) {
        cout << amr.size() << " 0" << endl;
        break;
      }
      amr.pb(a);
    }
  end:;
  }
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
#include <string.h>
const int N = 1000000;
int main() {
  int x, y, r, f, i;
  while (scanf("%d%d", &x, &y), x) {
    static int m[1000000];
    memset(m, 255, 4 * N);
    f = i = 0;
    do {
      r = x % y;
      if (r == 0)
        f = printf("%d 0\\n", i);
      if (m[r] >= 0)
        f = printf("%d %d\\n", m[r], i - m[r]);
      m[r] = i;
      x = r * 10;
      ++i;
    } while (!f);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <map>
#include <stdio.h>
int main() {
  int x, y, r, f, i;
  while (scanf("%d%d", &x, &y), x) {
    std::map<int, int> m;
    f = i = 0;
    do {
      r = x % y;
      if (r == 0)
        f = printf("%d 0\\n", i);
      if (m.find(r) != m.end())
        f = printf("%d %d\\n", m[r], i - m[r]);
      m[r] = i;
      x = r * 10;
      ++i;
    } while (!f);
  }
  return 0;
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

char ap[10000001];

int main() {

  int x, y;
  while (cin >> x >> y && (x | y)) {
    memset(ap, -1, sizeof(ap));
    int a, b;
    a = 0;
    b = 0;
    x *= 10;
    int sz = 0;
    ap[x] = sz++;
    while (1) {
      if (x < y)
        x *= 10;
      else {
        x = x % y;
        x *= 10;
      }
      if (x == 0) {
        cout << sz << " " << 0 << endl;
        break;
      }
      if (ap[x] == -1)
        ap[x] = sz++;
      else {
        int i = ap[x];
        int band = sz - i;
        a = i;
        b = band;
        cout << a << " " << b << endl;
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {

  int x, y;
  while (cin >> x >> y && (x | y)) {
    map<int, int> ap;
    int a, b;
    a = 0;
    b = 0;
    x *= 10;
    ap[x] = ap.size() - 1;
    while (1) {
      if (x < y)
        x *= 10;
      else {
        x = x % y;
        x *= 10;
      }
      if (x == 0) {
        cout << ap.size() << " " << 0 << endl;
        break;
      }
      if (ap.find(x) == ap.end())
        ap[x] = ap.size() - 1;
      // if(find(seq.begin(),seq.end(),x)==seq.end())seq.push_back(x);
      else {
        int i = ap[x];
        // for(i=0;i<(int)seq.size();i++)if(seq[i]==x)break;
        int band = ap.size() - i;
        a = i;
        b = band;
        cout << a << " " << b << endl;
        break;
      }
    }
  }

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

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  for (;;) {
    int x, y;
    cin >> x >> y;
    if (x == 0)
      return 0;

    vector<int> memo(y, -1);
    for (int i = 0;; ++i) {
      if (memo[x] != -1) {
        if (x == 0)
          cout << (i - 1) << ' ' << 0 << endl;
        else
          cout << memo[x] << ' ' << (i - memo[x]) << endl;
        break;
      }
      memo[x] = i;
      x *= 10;
      x %= y;
    }
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  for (;;) {
    int x, y;
    cin >> x >> y;
    if (x == 0)
      return 0;

    map<pair<int, int>, int> m;
    for (int i = 0;; ++i) {
      x *= 10;
      int z = x / y;
      x %= y;
      if (m.find(make_pair(x, z)) != m.end()) {
        if (x == 0)
          cout << (i - 1) << ' ' << 0 << endl;
        else
          cout << m[make_pair(x, z)] << ' ' << (i - m[make_pair(x, z)]) << endl;
        break;
      }
      m[make_pair(x, z)] = i;
    }
  }
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
int calc(int y) {}

// LookUp Version
const int N = 1000000;
int eulerPhi(int n) {
  static int lookup = 0, p[N], f[N];
  if (!lookup) {
    REP(i, N) p[i] = 1, f[i] = i;
    for (int i = 2; i < N; ++i) {
      if (p[i]) {
        f[i] -= f[i] / i;
        for (int j = i + i; j < N; j += i)
          p[j] = 0, f[j] -= f[j] / i;
      }
    }
    lookup = 1;
  }
  return f[n];
}

void naive(int x, int y) {
  int pos = -1, len = -1;
  map<int, int> loop;
  int l = 0;
  while (1) {
    loop[x] = l++;
    x = x * 10;
    x %= y;
    if (loop.count(x)) {
      pos = loop[x];
      if (!x)
        len = 0;
      else
        len = l - loop[x];
      break;
    }
  }
  cout << pos << " " << len << endl;
}

char use[1000100];
int answer[1000100];
#include <cstring>
int calclen(int y) {
  if (answer[y])
    return answer[y];
  memset(use, 0, y);
  int c = 1;
  int len = 0;
  while (use[c] == 0) {
    use[c] = 1;
    c = c * 10 % y;
    len++;
  }
  return answer[y] = len;
}
int smart(int x, int y) {
  int g = __gcd(x, y);
  x /= g;
  y /= g;
  int chk = y;
  int two = 0, five = 0;
  while (chk % 2 == 0)
    chk /= 2, two++;
  while (chk % 5 == 0)
    chk /= 5, five++;
  int pos = max(two, five);
  if (chk == 1) {
    cout << pos << " " << 0 << endl;
    return 0;
  }
  cout << pos << " " << calclen(chk) << endl;
}
int main() {
  int x, y;
  map<int, pair<int, int>> o;

  while (cin >> x >> y && x) {
    // naive(x,y);
    smart(x, y);
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;

int main() {
  int x, y;
  map<int, pair<int, int>> o;
  while (cin >> x >> y && x) {
    int g = __gcd(x, y);
    x /= g;
    y /= g;
    int l = 0;
    int pos = -1, len = -1;
    if (o.count(y))
      pos = o[y].first, len = o[y].second;
    if (len == -1) {
      map<int, int> loop;
      while (1) {
        loop[x] = l++;
        x = x * 10;
        x %= y;
        if (loop.count(x)) {
          pos = loop[x];
          if (!x)
            len = 0;
          else
            len = l - loop[x];
          break;
        }
      }
      o[y] = make_pair(pos, len);
    }
    cout << pos << " " << len << endl;
  }
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double PI = acos(-1);
const double EPS = 1e-8;

int table[1000000];

int main() {
  int x, y;
  while (cin >> x >> y, x || y) {
    memset(table, -1, sizeof(table));
    int cnt = 0;
    while (1) {
      if (x == 0) {
        cout << cnt << " 0" << endl;
        break;
      }
      if (table[x] != -1) {
        cout << table[x] << " " << cnt - table[x] << endl;
        break;
      }
      table[x] = cnt++;
      x *= 10;
      x %= y;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int x, y;
  while (cin >> x >> y, x || y) {
    map<int, int> mp;
    int cnt = 0;
    while (1) {
      if (x == 0) {
        cout << cnt << " 0" << endl;
        break;
      }
      if (mp.count(x)) {
        cout << mp[x] << " " << cnt - mp[x] << endl;
        break;
      }
      mp[x] = cnt++;
      x *= 10;
      x %= y;
    }
  }
}
Problem p01172 (C++) — buggy submission, verdict: Runtime Error

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

int gcd(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  for (int r; (r = a % b) != 0;) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int x, y;
  while (cin >> x >> y && x != 0) {
    const int g = gcd(x, y);
    x /= g;
    y /= g;
    vector<int> seen(y, -1);
    seen[x] = 0;
    for (int c = 1;; c++) {
      x = (10 * x) % y;
      if (x == 0) {
        cout << c << " 0" << endl;
        break;
      } else if (seen[x] != -1) {
        cout << seen[x] << ' ' << c - seen[x] << endl;
        break;
      }
      seen[x] = c;
    }
  }
  return 0;
}

Error: -8

Fixed submission:

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

int gcd(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  for (int r; (r = a % b) != 0;) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int x, y;
  while (cin >> x >> y) {
    const int g = gcd(x, y);
    x /= g;
    y /= g;
    vector<int> seen(y, -1);
    seen[x] = 0;
    for (int c = 1;; c++) {
      x = (10 * x) % y;
      if (x == 0) {
        cout << c << " 0" << endl;
        break;
      } else if (seen[x] != -1) {
        cout << seen[x] << ' ' << c - seen[x] << endl;
        break;
      }
      seen[x] = c;
    }
  }
  return 0;
}
Problem p01172 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, a) repi(i, 0, a)
#define repd(i, a, b) for (int i = (a); i >= (b); i--)
#define repit(i, a)                                                            \\
  for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(), (u).end()
#define rall(u) (u).rbegin(), (u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)), (u).end)

#define pb push_back
#define mp makek_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int x, y;
int done[1000003];
int main() {
  while (cin >> x >> y, x) {
    memset(done, -1, sizeof(done));
    int cnt = 0;
    while (true) {
      x -= y * (x / y);

      if (x == 0) {
        cout << cnt << " " << 0 << endl;
        break;
      }
      //	    cout << x << endl;
      if (done[x] != -1) { // end
        cout << done[x] << " " << cnt - done[x] << endl;
        break;
      }
      done[x] = cnt;
      x *= 10;

      cnt++;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, a) repi(i, 0, a)
#define repd(i, a, b) for (int i = (a); i >= (b); i--)
#define repit(i, a)                                                            \\
  for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define all(u) (u).begin(), (u).end()
#define rall(u) (u).rbegin(), (u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)), (u).end)

#define pb push_back
#define mp makek_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int x, y;
int done[1000003];
int main() {
  while (cin >> x >> y, x) {
    memset(done, -1, sizeof(done));
    int cnt = 0;
    while (true) {
      if (x == 0) {
        cout << cnt - 1 << " " << 0 << endl;
        break;
      }
      if (done[x] != -1) { // end
        cout << done[x] - 1 << " " << cnt - done[x] << endl;
        break;
      }
      done[x] = cnt;
      x -= y * (x / y);
      x *= 10;
      cnt++;
    }
  }
  return 0;
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#define MAX 10000000
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef pair<int, int> P;
int used[MAX];

P getRecurringCycle(int fraction, int denominator) {
  rep(i, MAX) used[i] = -1;
  fraction *= 10;
  used[fraction] = 0;
  int cnt = 0;
  while (true) {
    cnt++;
    fraction -= fraction / denominator * denominator;
    fraction *= 10;
    if (fraction == 0)
      return P(cnt, 0);
    if (used[fraction] != -1)
      break;
    used[fraction] = cnt;
  }
  return P(used[fraction], cnt - used[fraction]);
}

int main() {
  int x, y;
  while (cin >> x >> y, x | y) {
    P p = getRecurringCycle(x, y);
    cout << p.first << " " << p.second << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef pair<int, int> P;

P getRecurringCycle(int fraction, int denominator) {
  fraction *= 10;
  map<int, int> used;
  used[fraction] = 0;
  int cnt = 0;
  while (true) {
    cnt++;
    fraction -= fraction / denominator * denominator;
    fraction *= 10;
    if (fraction == 0)
      return P(cnt, 0);
    if (used.find(fraction) != used.end())
      break;
    used[fraction] = cnt;
  }
  return P(used[fraction], cnt - used[fraction]);
}

int main() {
  int x, y;
  while (cin >> x >> y, x | y) {
    P p = getRecurringCycle(x, y);
    cout << p.first << " " << p.second << endl;
  }
  return 0;
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define MP make_pair

typedef long long LL;
typedef pair<int, int> PII;

int main() {

  int x, y;
  while (cin >> x >> y, x || y) {
    vector<int> v(1e6, -1);
    for (int i = 0;; ++i) {
      if (v[x] >= 0) {
        cout << v[x] << ' ' << (x ? i - v[x] : 0) << endl;
        break;
      }
      v[x] = i;
      x *= 10;
      x %= y;
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define MP make_pair

typedef long long LL;
typedef pair<int, int> PII;

int main() {

  int x, y;
  while (cin >> x >> y, x || y) {
    map<pair<int, int>, int> m;
    for (int i = 0;; ++i) {
      if (m.find(MP(x, y)) != m.end()) {
        cout << m[MP(x, y)] << ' ' << (x ? i - m[MP(x, y)] : 0) << endl;
        break;
      }
      m[MP(x, y)] = i;
      x *= 10;
      x %= y;
    }
  }
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int x, y;
  while (cin >> x >> y && (x || y)) {
    unordered_map<int, int> mp;
    int cnt = 0;
    while (!mp.count(x % y)) {
      if (x % y == 0)
        break;
      mp[x % y] = cnt++;
      x %= y;
      x *= 10;
    }
    if (x % y == 0) {
      cout << cnt << " " << 0 << endl;
    } else {
      cout << mp[x % y] << " " << cnt - mp[x % y] << endl;
    }
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int x, y;
  while (cin >> x >> y && (x || y)) {
    map<int, int> mp;
    int cnt = 0;
    while (!mp.count(x % y)) {
      if (x % y == 0)
        break;
      mp[x % y] = cnt++;
      x %= y;
      x *= 10;
    }
    if (x % y == 0) {
      cout << cnt << " " << 0 << endl;
    } else {
      cout << mp[x % y] << " " << cnt - mp[x % y] << endl;
    }
  }
}
Problem p01172 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

template <class T> void debug(T begin, T end) {
  for (T i = begin; i != end; ++i)
    cerr << *i << " ";
  cerr << endl;
}
inline bool valid(int x, int y, int W, int H) {
  return (x >= 0 && y >= 0 && x < W && y < H);
}

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int x, y;
  while (scanf("%d %d", &x, &y) != EOF && y != 0) {
    int memo[1000000] = {};
    for (int t = 1;; t++) {
      if (memo[x]) {
        printf("%d %d\\n", memo[x] - 1, t - memo[x]);
        break;
      } else if (x == 0) {
        printf("%d 0\\n", t - 1);
        break;
      }
      memo[x] = t;
      x = (x * 10) % y;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FORIT(i, c)                                                            \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)

template <class T> void debug(T begin, T end) {
  for (T i = begin; i != end; ++i)
    cerr << *i << " ";
  cerr << endl;
}
inline bool valid(int x, int y, int W, int H) {
  return (x >= 0 && y >= 0 && x < W && y < H);
}

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int x, y;
  while (cin >> x >> y && y != 0) {
    map<int, int> memo;
    for (int t = 1;; t++) {
      if (memo.count(x)) {
        printf("%d %d\\n", memo[x] - 1, t - memo[x]);
        break;
      } else if (x == 0) {
        printf("%d 0\\n", t - 1);
        break;
      }
      memo[x] = t;
      x = (x * 10) % y;
    }
  }
  return 0;
}