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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  long long int k = 7;
  long long int cnt = 1;
  while (1) {
    if (k % n == 0) {
      cout << cnt << endl;
      break;
    }
    if (cnt > n) {
      cout << "-1" << endl;
      break;
    }
    k = (k % n) * 10 + 7;
    cnt++;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  long long int k = 7;
  long long int cnt = 1;
  while (1) {
    if (k % n == 0) {
      cout << cnt << endl;
      break;
    }
    if (cnt > n) {
      cout << "-1" << endl;
    }
    k = (k % n) * 10 + 7;
    cnt++;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int K;
  cin >> K;
  int i;
  int ans = 1;
  vector<int> modK(1000010);
  modK.at(0) = 0;

  for (i = 1; i <= K; i++) {
    modK.at(i) = (modK.at(i - 1) * 10 + 7) % K;
  }

  for (i = 1; i <= K; i++) {
    if (modK.at(i) == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int K;
  cin >> K;
  int ans = 1;

  long long int seven = 7;
  int modK = 7;

  while (seven % K != 0) {
    modK = modK * 10 % K;
    if (modK == 0) {
      cout << -1 << endl;
      return 0;
    }

    seven += modK;
    ans++;
  }

  cout << ans << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

const int MAX_N = 100000000;
int digs[MAX_N];
int K;
int max_idx = 0;

void update_digs(int idx, int v) {
  digs[idx] += v;
  if (digs[idx] > 9) {
    digs[idx + 1] += digs[idx] / 10;
    digs[idx] %= 10;
  }
  if (digs[idx])
    max_idx = std::max(max_idx, idx);
  if (digs[idx + 1])
    max_idx = std::max(max_idx, idx + 1);
}

int main() {
  scanf("%d", &K);
  int idx = 0;
  int kk = K;
  max_idx = -1;
  while (kk) {
    max_idx++;
    kk /= 10;
  }
  while (1) {
    int found = -1;
    for (int m = 0; m <= 9; ++m) {
      int v = (m * (K % 10) + digs[idx]) % 10;
      if (v == 7) {
        found = m;
        break;
      }
    }
    if (found != -1) {
      int kk = K;
      for (int i = 0; kk; ++i) {
        int v = kk % 10;
        update_digs(idx + i, found * v);
        kk /= 10;
      }
    }
    // printf("%d %d %d %d\\n", found, idx, max_idx, digs[idx]);
    if (idx >= max_idx && digs[idx] == 7)
      break;
    if (found == -1 && digs[idx] != 7) {
      printf("-1\\n");
      return 0;
    }

    idx++;
    if (idx > MAX_N - 10) {
      printf("-1\\n");
      // printf("BROKEN\\n");
      return 0;
    }
  }
  printf("%d\\n", max_idx + 1);
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>

const int MAX_N = 100000000;
int digs[MAX_N];
int K;
int max_idx = 0;

void update_digs(int idx, int v) {
  digs[idx] += v;
  if (digs[idx] > 9) {
    digs[idx + 1] += digs[idx] / 10;
    digs[idx] %= 10;
  }
  if (digs[idx])
    max_idx = std::max(max_idx, idx);
  if (digs[idx + 1])
    max_idx = std::max(max_idx, idx + 1);
}

int main() {
  scanf("%d", &K);
  int idx = 0;
  while (1) {
    int found = 0;
    for (int m = 0; m <= 9; ++m) {
      int v = (m * (K % 10) + digs[idx]) % 10;
      if (v == 7) {
        found = m;
        break;
      }
    }
    if (found == 0 && idx >= max_idx && digs[idx] == 7)
      break;
    if (found == 0 && digs[idx] != 7) {
      printf("-1\\n");
      return 0;
    }
    int kk = K;
    for (int i = 0; kk; ++i) {
      int v = kk % 10;
      update_digs(idx + i, found * v);
      kk /= 10;
    }
    idx++;
  }
  printf("%d\\n", max_idx + 1);
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
#define endl '\\n'
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    index_set;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using ii = pair<int, int>;
#define f first
#define s second
#define mp make_pair
#define pb push_back
const int m = 1000000007;
int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(nullptr);
  int k;
  cin >> k;
  int n = 0;
  int ans = 0;
  for (int i = 1; i < 2 * k; i++) {
    n = (n * 10 + 7) % k;
    if (!n) {
      cout << i << endl;
      return 0;
    }
    ans = -1;
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
#define endl '\\n'
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    index_set;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using ii = pair<int, int>;
#define f first
#define s second
#define mp make_pair
#define pb push_back
const int m = 1000000007;
int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(nullptr);
  int k;
  cin >> k;
  ll ans = 7;
  if (!k & 1)
    cout << -1 << endl;
  int c = 0;
  while (1) {
    c += 1;
    if (ans % k == 0)
      break;
    ans = (ans * 10 + 7) % k;
  }
  cout << c << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  cin >> k;
  if (k % 2 == 0)
    cout << "-1";
  else if (k % 5 == 0)
    cout << "-1";
  else {
    int nana = 7;
    int ans = 1;
    for (int i = 0; i <= k; i++) {
      if (nana % k == 0) {
        cout << ans;
        break;
      } else if (i == k) {
        cout << "-1";
      }
      ans++;
      nana = (nana * 10 + 7) % k;
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  cin >> k;
  if (k % 2 == 0)
    cout << "-1";
  else if (k % 5 == 0)
    cout << "-1";
  else {
    int nana = 7;
    int ans = 1;
    while (true) {
      if (nana % k == 0) {
        cout << ans;
        break;
      }
      ans++;
      nana = nana * 10 + 7;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  ll k;
  cin >> k;

  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }

  bool flag = true;
  ll rem = 7;
  ll ans = 1;
  while (flag) {
    rem = rem % k;
    if (rem == 0) {
      flag = false;
    } else {
      rem = rem * 10 + 7;
      ans++;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
  ll k;
  cin >> k;

  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }

  bool flag = true;
  ll rem = 7;
  ll ans = 1;
  while (flag) {
    rem = rem % k;
    if (rem == 0) {
      flag = false;
    } else {
      rem = rem * 10 + 7;
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define has(c, i) ((c).find(i) != end(c))
#define has_str(s, c) ((s).find(c) != string::npos)
typedef long long ll;
int main() {
#ifdef online_judge
  freopen("input.txt", "rt", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll k;
  cin >> k;
  ll n = 7;
  map<int, int> done;
  if (k % 2 == 0)
    cout << -1;
  else {
    int cnt = 1;
    while (true) {
      if (n % k == 0) {
        cout << cnt;
        return 0;
      }
      n *= 10;
      n += 7;
      n %= k;
      if (done[n]) {
        cout << -1;
        return 0;
      }
      cnt++;
      done[n] = true;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using indexed_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define all(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define has(c, i) ((c).find(i) != end(c))
#define has_str(s, c) ((s).find(c) != string::npos)
typedef long long ll;
int main() {
#ifdef online_judge
  freopen("input.txt", "rt", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  ll k;
  cin >> k;
  ll n = 7;
  if (k % 2 == 0)
    cout << -1;
  else {
    int cnt = 1;
    while (true) {
      if (n % k == 0) {
        cout << cnt;
        return 0;
      }
      cnt++;
      n *= 10;
      n += 7;
      n %= k;
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  unordered_map<int, int> a;
  long long int p = 7 % k;
  int ans = 1;
  a[p] = 1;
  while (p) {
    ans++;
    p = (10 * p + 7) % k;
    if (a[p] == 1)
      break;
    a[p] = 1;
  }
  if (p == 0)
    cout << ans << endl;
  else
    cout << "-1" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int k;
  cin >> k;
  long long int p = 7 % k;
  long long int t = p;
  int ans = 1;
  if (k % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  while (t) {
    ans++;
    t = (10 * t + p) % k;
  }
  cout << ans << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define ll long long

int main() {
  ll k, a = 1, b;
  cin >> k;
  b = 7 % k;

  while (b) {
    if (a > 1000000) {
      a = -1;
      break;
    }

    a++;
    b *= 10;
    b += 7;
    b %= k;
  }

  cout << a << "\\n";
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define ll long long

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

  if (!(k % 2) && k % 10 == 5) {
    cout << -1 << endl;
  } else {
    int ans = 0, a = 0;
    while (++ans) {
      a = (a * 10 + 7) % k;
      if (!a) {
        cout << ans << endl;
        break;
      }
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

// #include"bits/stdc++.h"
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define rep(i, j) FOR(i, 0, j, 1)
#define MP make_pair
#define PB push_back
#define endl "\\n"
#define MOD 1000000007
#define DEB(x) cout << "##" << x << "##" << endl
const int INF = (int)2e9 + 9;
const int SIZE = (int)2e5 + 5;
// Brute force answers(BINARY SEARCH) symmetry
// Change perspective
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1;
  } else {
    int min1 = 0, temp = k;
    while (temp > 0) {
      temp /= 10;
      min1++;
    }
    int ans = 0, pref = 0;
    ll cnt = 7;
    while (1) {
      ans++;
      pref += cnt;
      pref %= k;
      if (pref == 0) {
        break;
      }
      cnt = (cnt * 10) % k;
      if (ans >= (int)1e6) {
        ans = -1;
        break;
      }
    }
    cout << ans;
  }
}

Error: TLE

Fixed submission:

// #include"bits/stdc++.h"
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define rep(i, j) FOR(i, 0, j, 1)
#define MP make_pair
#define PB push_back
#define endl "\\n"
#define MOD 1000000007
#define DEB(x) cout << "##" << x << "##" << endl
const int INF = (int)2e9 + 9;
const int SIZE = (int)2e5 + 5;
// Brute force answers(BINARY SEARCH) symmetry
// Change perspective
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1;
  } else {
    int min1 = 0, temp = k;
    while (temp > 0) {
      temp /= 10;
      min1++;
    }
    int ans = 0, pref = 0;
    ll cnt = 7;
    while (1) {
      ans++;
      pref += cnt;
      pref %= k;
      if (pref == 0) {
        break;
      }
      cnt = (cnt * 10) % k;
    }
    cout << ans;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve(int T) {
  int k, ans = 1;
  int tmp = 7;
  scanf("%d", &k);
  /*if(k%2==0){
          puts("-1");
          return;
  }*/
  while (tmp % k) {
    tmp = (tmp * 10 + 7) % k;
    ans++;
    if (ans > 1e7)
      break;
  }
  if (ans > 1e7)
    puts("-1");
  else
    printf("%d", ans);
}
signed main() {
  int t = 1;
  // scanf("%d",&t);
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve(int T) {
  int k, ans = 1;
  int tmp = 7;
  scanf("%d", &k);
  if (k % 2 == 0) {
    puts("-1");
    return;
  }
  while (tmp % k) {
    tmp = (tmp * 10 + 7) % k;
    ans++;
  }
  printf("%d", ans);
}
signed main() {
  int t = 1;
  // scanf("%d",&t);
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long k;
  cin >> k;

  // 偶数は排除
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }

  long long count = 0;
  long long i = 1;
  long long number = 7;
  while (1) {
    if (number % k == 0) {
      count = i;
      break;
    }

    number = (number % k) * 10 + 7;
    i++;
  }

  cout << count << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long k;
  cin >> k;

  // 偶数は排除
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }

  long long count = 0;
  long long i = 1;
  long long number = 7;
  while (1) {
    if (number % k == 0) {
      count = i;
      break;
    }

    number = number * 10 + 7;
    i++;
  }

  cout << count << endl;

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

#include <bits/stdc++.h>
#define ll long long
#define rep(i, a, b) for (long long i = a; i < b; i += 1)
#define repr(i, a, b) for (long long i = a; i <= b; i += 1)
#define vec vector<ll>
#define map map<char, int>
#define repa(p, A) for (auto p : A)
#define pb push_back
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
const double PI = acos(-1);
const ll INF = 1000000;
using namespace std;

int main() {
  ll K;
  cin >> K;
  vec A(K);
  A[0] = 7;
  rep(i, 0, K - 1) { A[i + 1] = (A[i] * 10 + 7) % K; }
  rep(i, 0, K) {
    if (A[i] % K == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}


Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define rep(i, a, b) for (long long i = a; i < b; i += 1)
#define repr(i, a, b) for (long long i = a; i <= b; i += 1)
#define vec vector<ll>
#define map map<char, int>
#define repa(p, A) for (auto p : A)
#define pb push_back
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
const double PI = acos(-1);
const ll INF = 1000000;
using namespace std;

int main() {
  ll K;
  cin >> K;
  vec A(K);
  A[0] = 7;
  rep(i, 0, K) { A[i + 1] = (A[i] * 10 + 7) % K; }
  rep(i, 0, K) {
    if (A[i] % K == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int K, n, cnt;
  cin >> K;
  n = 7 % K;
  bool finish = true;
  cnt = 1;
  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1;
    finish = false;
  }
  while (finish) {
    if (n == 0) {
      cout << cnt;
      break;
    } else {
      n = (n * 10 + 7) % K;
      cnt++;
    }
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int K, n, cnt;
  cin >> K;
  n = 7;
  bool finish = true;
  cnt = 1;
  if (K % 2 == 0) {
    cout << -1;
    finish = false;
  }
  while (finish) {
    if (n % K == 0) {
      cout << cnt;
      break;
    } else {
      n = (n * 10 + 7) % K;
      cnt++;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll>::iterator itll;
typedef long double ld;
typedef map<ll, ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define all(vl) vl.begin(), vl.end()
#define m_p make_pair
#define sz(a) sizeof(a)
#define forn(mp, it) for (it = mp.begin(); it != mp.end(); it++)
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define FORE(i, a, n) FOR(i, a, n + 1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl
#define PI 3.14159265358979323846

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << "-1\\n";
    return 0;
  }
  ll tmp = 7 % k;
  ll ans = 1;
  while (tmp != 0) {
    tmp = tmp * 10 + 7;
    tmp = tmp % k;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll>::iterator itll;
typedef long double ld;
typedef map<ll, ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define one 1.0
#define inf 1000000000000000000
#define all(vl) vl.begin(), vl.end()
#define m_p make_pair
#define sz(a) sizeof(a)
#define forn(mp, it) for (it = mp.begin(); it != mp.end(); it++)
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define FORE(i, a, n) FOR(i, a, n + 1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl
#define PI 3.14159265358979323846

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1\\n";
    return 0;
  }
  ll ans = 1;
  ll tmp = 7 % k, b = 7 % k;
  if (tmp == 0) {
    cout << ans << endl;
    return 0;
  }
  while (1) {
    ans++;
    tmp += (b * 10) % k;
    tmp = tmp % k;
    b = (b * 10) % k;
    if (tmp == 0)
      break;
  }
  cout << ans << Endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int K;
  cin >> K;
  int L, i = 1;
  int ans = -1;
  if (K % 7 == 0)
    L = 9 * K / 7;
  else
    L = 9 * K;
  if (L % 2 != 0 && L % 5 != 0) {
    int m = 10 % L;
    if (m == 1)
      ans = 1;
    else {
      do {
        m = m * 10 % L;
        i++;
      } while (m != 1);
      ans = i;
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int K;
  cin >> K;
  int L, i = 1;
  int ans = -1;
  if (K % 7 == 0)
    L = 9 * K / 7;
  else
    L = 9 * K;
  if (L % 2 != 0 || L % 5 != 0) {
    int m = 10 % L;
    if (m == 1)
      ans = 1;
    else {
      do {
        m = m * 10 % L;
        i++;
      } while (m != 1);
      ans = i;
    }
  }
  cout << ans << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

int main() {
  long long K;
  std::cin >> K;
  if (K % 2 == 0 || K % 5 == 0) {
    std::cout << -1 << std::endl;
    return 0;
  }
  long long digit = 1;
  long long N = 7 % K;
  while (N != 0) {
    N = (N * 10 + 7) % K;
    ++digit;
  }
  std::cout << digit << std::endl;
}


Error: TLE

Fixed submission:

#include <iostream>

int main() {
  long long K;
  std::cin >> K;
  if (K % 2 == 0 || K % 5 == 0) {
    std::cout << -1 << std::endl;
    return 0;
  }
  long long digit{1};
  long long N{7};
  while (true) {
    if (N % K == 0 && N > K)
      break;
    else {
      N = (N * 10 + 7) % K;
      ++digit;
    }
  }
  std::cout << digit << std::endl;

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

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

int main() {
  int k;
  scanf("%d", &k);
  long long rem = 0;
  if (k % 2 == 0) {
    printf("-1\\n");
  } else {
    int step = 0;
    while (1) {
      step++;
      rem *= 10;
      rem += 7;
      rem %= k;
      if (rem == 0)
        break;
      if (step > 10000000) {
        printf("-1\\n");
        return 0;
      }
    }
    printf("%d\\n", step);
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int k;
  scanf("%d", &k);
  int rem = 0;
  if (k % 2 == 0) {
    printf("-1\\n");
  } else {
    int step = 0;
    while (1) {
      step++;
      rem *= 10;
      rem += 7;
      rem %= k;
      if (rem == 0)
        break;
    }
    printf("%d\\n", step);
  }
}