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

#include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
#define ll long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mod (ll)(1e9 + 7)
#define inf (ll)(3e18 + 7)
#define pi (double)acos(-1.0)
#define P pair<int, int>
#define PiP pair<ll, pair<ll, ll>>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;

int main() {
  ll k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll now = 7 % k, i = 1;
  while (true) {
    if (now % k == 0) {
      cout << i << endl;
      return 0;
    }
    i++;
    now *= 10;
    now += 7;
    now %= k;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else {
    return false;
  }
}
#define ll long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mod (ll)(1e9 + 7)
#define inf (ll)(3e18 + 7)
#define pi (double)acos(-1.0)
#define P pair<int, int>
#define PiP pair<ll, pair<ll, ll>>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;

int main() {
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll now = 7 % k, i = 1;
  while (true) {
    if (now % k == 0) {
      cout << i << endl;
      return 0;
    }
    i++;
    now *= 10;
    now += 7;
    now %= k;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL << 60;
// int INF = numeric_limits<int>::max();

int main(int, char **) {
  int k;
  cin >> k;
  if (k % 7 == 0)
    k /= 7;
  int ret = -1;
  ll prev = 1;
  for (int i = 1; i < k + 3; i++) {
    ll now;
    now = (10 * prev) % (9 * k);
    if (now == 1) {
      ret = i;
      break;
    } else {
      prev = now;
    }
  }
  cout << ret << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL << 60;
// int INF = numeric_limits<int>::max();

int main(int, char **) {
  int k;
  cin >> k;
  if (k % 7 == 0)
    k /= 7;
  int ret = -1;
  int cnt = 1;
  ll amari = 0;
  ll prev = 1;
  while (true) {
    ll now;
    if (cnt == 1)
      now = 1 % k;
    else
      now = (prev * 10) % k;
    amari += now;
    if (amari % k == 0) {
      ret = cnt;
      break;
    } else if (now == 0) {
      ret = -1;
      break;
    } else {
      cnt++;
      prev = now;
    }
  }
  cout << ret << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, x, n) for (int i = x; i < (n); ++i)

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll now = 7;
  rep2(i, 1, 1e7) {
    if (now % k == 0) {
      cout << i << endl;
      return 0;
    }
    now *= 10;
    now += 7;
    now %= k;
  }
  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, x, n) for (int i = x; i < (n); ++i)

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int count = 0;
  int num = k;
  ll x = 0;
  while (num) {
    count++;
    num /= 10;
    x = x * 10 + 7;
  }
  while (x % k != 0) {
    count++;
    x = x * 10 + 7;
    x %= k;
  }
  cout << count << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long K;
  cin >> K;
  if (K == 7 || K == 1) {
    cout << "1" << endl;
    return 0;
  }
  long long amari = fmod(7, K);
  for (long long i = 1; i <= K; i++) {
    if (fmod((amari * 10 + 7), K) == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    amari = fmod((amari * 10 + 7), K);
  }
  cout << -1 << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long K;
  cin >> K;
  if (fmod(K, 2) == 0 || fmod(K, 5) == 0) {
    cout << "-1" << endl;
    return 0;
  }
  K *= 9;
  if (fmod(K, 7) == 0)
    K /= 7;
  for (long double i = 1;; i++) {
    if (fmod(pow(10, i), K) == 1) {
      cout << i << endl;
      break;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define IOS                                                                    \\
  {                                                                            \\
    ios::sync_with_stdio(false);                                               \\
    cin.tie(0);                                                                \\
    cout.tie(0);                                                               \\
  }
#define ll long long
ll powermod(ll x, ll ex, ll md) {
  ll ans = 1ll;
  while (ex > 0) {
    if (ex & 1ll)
      ans = (ans * x) % md;
    ex >>= 1ll;
    x = (x * x) % md;
  }
  return ans;
}

int main() {
  IOS;
  ll n;
  cin >> n;
  // vector<ll> factor;

  // for(ll i=1;i*i<=n;++i){
  //     if(n%i==0){
  //         ll div1=i,div2=n/i;
  //         factor.push_back(div1);
  //         if(div1 != div2) factor.push_back(div2);
  //     }
  // }

  // for(ll i=0;i<(int)(factor.size());i++) cout << factor[i] <<" ";

  ll ans = -1;
  if (n == 7) {
    cout << 1 << "\\n";
    return 0;
  } else if (n % 2 == 0) {
    cout << -1 << "\\n";
    return 0;
  }

  n *= 9;
  for (ll i = 1; i <= 1e6; i++) {
    ll b = 3;
    ll a = powermod(10, i, n);
    a %= n;
    (a) = (a - 1 + n) % n;

    a = ((a % n) * 7) % n;
    if (a == 0) {
      ans = i;
      break;
    }
  }
  if (ans != -1)
    cout << ans << "\\n";
  else
    cout << -1 << "\\n";
}


Error: TLE

Fixed submission:

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

#define IOS                                                                    \\
  {                                                                            \\
    ios::sync_with_stdio(false);                                               \\
    cin.tie(0);                                                                \\
    cout.tie(0);                                                               \\
  }
#define ll long long
ll powermod(ll x, ll ex, ll md) {
  ll ans = 1ll;
  while (ex > 0) {
    if (ex & 1ll)
      ans = (ans * x) % md;
    ex >>= 1ll;
    x = (x * x) % md;
  }
  return ans;
}

int main() {
  IOS;
  ll n;
  cin >> n;
  // vector<ll> factor;

  // for(ll i=1;i*i<=n;++i){
  //     if(n%i==0){
  //         ll div1=i,div2=n/i;
  //         factor.push_back(div1);
  //         if(div1 != div2) factor.push_back(div2);
  //     }
  // }

  // for(ll i=0;i<(int)(factor.size());i++) cout << factor[i] <<" ";

  ll ans = -1;
  if (n == 7) {
    cout << 1 << "\\n";
    return 0;
  } else if (n % 2 == 0) {
    cout << -1 << "\\n";
    return 0;
  }

  n *= 9;
  for (ll i = 1; i <= 1e7; i++) {
    ll b = 3;
    ll a = powermod(10, i, n);
    a %= n;
    (a) = (a - 1 + n) % n;

    a = ((a % n) * 7) % n;
    if (a == 0) {
      ans = i;
      break;
    }
  }
  if (ans != -1)
    cout << ans << "\\n";
  else
    cout << -1 << "\\n";
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <random>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using ull = unsigned long long;
const ll K_MAX = 1e5 + 5;
const ll Lmax = ll(1e18);
const ll INF = 1e6;
const int Nmax = 2e5 + 1;
const int Nd = 61;

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  bool ok = true;
  int i = 1;
  int now1 = 0;
  int now2 = 7;
  int start = now2 % k;
  int ans = 0;
  while (ok) { //
    now2 = now2 % k;
    now1 = (now1 + now2) % k;
    if (now1 == 0) {
      ans = i;
      cout << i << endl;
      ok = false;
      break;
    }
    now2 *= 10;
    if (now1 == start && i > 1) {
      cout << -1 << endl;
      return 0;
    }
    i++;
    if (i > k) {
      cout << -1 << endl;
      return 0;
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <random>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using ull = unsigned long long;
const ll K_MAX = 1e5 + 5;
const ll Lmax = ll(1e18);
const ll INF = 1e6;
const int Nmax = 2e5 + 1;
const int Nd = 61;

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  bool ok = true;
  int i = 1;
  int now1 = 0;
  int now2 = 7;
  int start = now2 % k;
  int ans;
  while (ok) { //
    now2 = now2 % k;
    now1 = (now1 + now2) % k;
    if (now1 == 0) {
      ans = i;
      cout << i << endl;
      ok = false;
      break;
    }
    now2 *= 10;
    if (now1 == start && i > 1) {
      cout << -1 << endl;
      return 0;
    }
    i++;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int K;
  // 入力
  cin >> K;
  int ans = -1;
  int seven = 0;
  for (int i = 1; i <= 1000001; i++) {
    seven = 10 * seven % K + 7;
    if (seven % K == 0) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int K;
  // 入力
  cin >> K;
  int ans = -1;
  int o;
  o = K / 10;
  if (K % 2 != 0 and K % 5 != 0) {
    for (int i = o; i >= 0; i++) {
      int seven = 0;
      for (int j = 0; j <= i; j++) {
        seven = seven + 7 * pow(10, j);
      }
      if (seven % K == 0) {
        ans = i + 1;
        break;
      }
    }
  }
  cout << ans << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

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

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (lol i = 0; i < lol(n); i++)
#define REPD(i, n) for (lol i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (lol i = a; i <= lol(b); i++)
#define FORD(i, a, b) for (lol i = a; i >= lol(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) lol(x.size())     // sizeをsize_tからllに直しておく
// 定数
#define PI 3.1415926535897932385 // pi
#define INF 1000000000000        // 10^12:極めて大きい値,∞
#define MOD 1000000007           // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 最大値最小値
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
  lol result{0};
  lol k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    result = -1;
  } else {
    lol l;
    if (k % 7 == 0)
      l = 9 * k / 7;
    else {
      l = 9 * k;
    }
    lol re{1};
    while (true) {
      re = (10 * re) % l;
      result++;
      // cout << re << endl;
      if (re == 1)
        break;
    }
  }

  cout << result << endl;
  return 0;
}

Error: 0

Fixed submission:

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

// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (lol i = 0; i < lol(n); i++)
#define REPD(i, n) for (lol i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (lol i = a; i <= lol(b); i++)
#define FORD(i, a, b) for (lol i = a; i >= lol(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) lol(x.size())     // sizeをsize_tからllに直しておく
// 定数
#define PI 3.1415926535897932385 // pi
#define INF 1000000000000        // 10^12:極めて大きい値,∞
#define MOD 1000000007           // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 最大値最小値
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
  lol result{0};
  lol k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 1;
  }
  lol l;
  if (k % 7 == 0)
    l = 9 * k / 7;
  else {
    l = 9 * k;
  }
  lol re{1};
  while (true) {
    re = (10 * re) % l;
    result++;
    // cout << re << endl;
    if (re == 1)
      break;
  }

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

#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type)                                          \\
  memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353LL;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end() {
#ifdef ONLINE
  printf("\\nTime used: %.6lf(s)\\n", ((double)TIME__END - TIME__START) / 1000);
  system("pause");
#endif
}
ll k;
ll ans;
ll now;

void solve() {
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0)
    return puts("-1"), void();
  ans = 1, now = 7;
  while (1) {
    if (now % k == 0)
      break;
    ans++;
    now = (now * 10) + 7;
    now %= k;
  }
  printf("%lld\\n", ans);
}

int main() {
  TIME__START = clock();
  int Test = 1;
  // scanf("%d", &Test);
  while (Test--)
    solve();
  TIME__END = clock();
  program_end();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type)                                          \\
  memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353LL;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end() {
#ifdef ONLINE
  printf("\\nTime used: %.6lf(s)\\n", ((double)TIME__END - TIME__START) / 1000);
  system("pause");
#endif
}
ll k;
ll ans;
ll now;

void solve() {
  cin >> k;
  if (k % 2 == 0)
    return puts("-1"), void();
  ans = 1, now = 7;
  while (1) {
    if (now % k == 0)
      break;
    ans++;
    now = (now * 10) + 7;
    now %= k;
  }
  printf("%lld\\n", ans);
}

int main() {
  TIME__START = clock();
  int Test = 1;
  // scanf("%d", &Test);
  while (Test--)
    solve();
  TIME__END = clock();
  program_end();
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int ans = 0;

int mod(int num, int k) {
  int re;
  int a;
  a = num / k;
  re = num - k * a;
  return re;
}
void func(int num, int k) {
  if (num % k == 0) {
    ans++;
  } else if (ans < k * 2) {
    num = mod(num, k);
    num = num * 10 + 7;
    ans++;

    // cout<<num<<endl;
    func(num, k);
  }
}
int main(void) {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  } else if (k == 1 || k == 7) {
    cout << "1" << endl;
    return 0;
  }
  int pre_num = 7;
  func(pre_num, k);

  if (ans < k * 2) {
    cout << ans << endl;
  } else
    cout << "-1" << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int ans = 0;

int mod(int num, int k) {
  int re;
  int a;
  a = num / k;
  re = num - k * a;
  return re;
}
void func(int num, int k) {
  if (num % k == 0) {
    ans++;
  } else {
    num = mod(num, k);
    num = num * 10 + 7;
    ans++;

    // cout<<num<<endl;
    func(num, k);
  }
}
int main(void) {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  } else if (k == 1 || k == 7) {
    cout << "1" << endl;
    return 0;
  }
  int pre_num = 7;
  func(pre_num, k);

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

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

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

  long long r = (abs(7 % K) <= abs(7 % K - K)) ? 7 % K : 7 % K - K;
  long long num = 1;
  long long min_r = r;
  while (true) {
    if (r == 0) {
      break;
    }

    r = (10 * r + 7) % K;
    r = (abs(r) <= abs(r - K)) ? r : r - K;
    num++;

    if (min_r == r) {
      cout << -1 << endl;
      return 0;
    }
    if (min_r > r) {
      min_r = r;
    }
  }
  cout << num << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

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

  long long r = (abs(7 % K) <= abs(7 % K - K)) ? 7 % K : 7 % K - K;
  long long num = 1;
  while (true) {
    if (r == 0) {
      break;
    }

    if ((9 * r + 7) % K == 0) {
      cout << -1 << endl;
      return 0;
    }

    r = (10 * r + 7) % K;
    r = (abs(r) <= abs(r - K)) ? r : r - K;
    num++;
  }
  cout << num << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9 + 7LL;

int main() {
  ll K;
  cin >> K;
  ll m = 0;
  ll f = 7 % K;
  ll c = 0;
  while (1) {
    c++;
    m += f;
    if (m % K == 0)
      break;
    f = f * 10 % K;
    m %= K;
    if (c > K) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << c << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9 + 7LL;

int main() {
  ll K;
  cin >> K;
  ll m = 0;
  ll f = 7 % K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll c = 0;
  while (1) {
    c++;
    m += f;
    if (m % K == 0)
      break;
    f = f * 10 % K;
    m %= K;
  }
  cout << c << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int k;
  cin >> k;
  int cnt = 0;
  for (int i = 1; i < 1e7; i++) {
    cnt = (cnt * 10 + 7) % k;
    if (cnt == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  int k;
  cin >> k;
  int cnt = 0;
  rep(i, 1e7) {
    cnt = (cnt * 10 + 7) % k;
    if (cnt == 0) {
      cout << i << endl;
    } else {
      cout << "-1" << endl;
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define dot cout << setprecision(20) << endl;
#define vsor(x) sort(x.begin(), x.end());
#define vrev(x) reverse(x.begin(), x.end());
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define move(i) for (int i = 0; i < 4; i++)
#define bit(b, n) for (int b = 0; b < (1 << (ll)(n)); b++)

using namespace std;

int main() {
  ll k;
  cin >> k;
  ll ans = 0;
  if (k % 5 == 0 || k % 2 == 0)
    cout << -1 << endl;
  else {
    int n = 0;
    while (true) {
      n = (n * 10 + 7) % k;
      ans++;
      if (n == 0) {
        break;
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define dot cout << setprecision(20) << endl;
#define vsor(x) sort(x.begin(), x.end());
#define vrev(x) reverse(x.begin(), x.end());
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define move(i) for (int i = 0; i < 4; i++)
#define bit(b, n) for (int b = 0; b < (1 << (ll)(n)); b++)

using namespace std;

int main() {
  ll k;
  cin >> k;
  ll ans = 1, t = 7;
  if (k % 5 == 0 || k % 2 == 0)
    cout << -1 << endl;
  else if (t % k == 0)
    cout << ans << endl;
  else {
    while (true) {
      t = t * 10 + 7;
      ans++;
      if (t % k == 0) {
        cout << ans << endl;
        break;
      }
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define pb push_back
#define fori(j, n) for (int i = j; i < n; i++)
#define forj(i, n) for (int j = i; j < n; j++)
#define fork(i, n) for (int k = i; k < n; k++)
#define ppb pop_back()
#define umap unordered_map
#define uset unordered_set
#define lli long long int

using namespace std;

void solve() {
  lli k;
  cin >> k;
  if (k % 2 == 0 or k % 5 == 0) {
    cout << -1;
    return;
  }
  lli ans = 0;
  int cnt = 0;
  while (1) {
    cnt++;
    ans = (ans * 10 + 7) % k;
    if (ans == 0)
      break;
  }
  cout << cnt;
}

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

  // int t;cin>>t;
  // while(t--)
  // {
  solve();
  // cout<<endl;
  // }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define fori(j, n) for (int i = j; i < n; i++)
#define forj(i, n) for (int j = i; j < n; j++)
#define fork(i, n) for (int k = i; k < n; k++)
#define ppb pop_back()
#define umap unordered_map
#define uset unordered_set
#define lli long long int

using namespace std;

void solve() {
  lli k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1;
    return;
  }
  lli ans = 0;
  int cnt = 0;
  while (1) {
    cnt++;
    ans = (ans * 10 + 7) % k;
    if (ans == 0)
      break;
  }
  cout << cnt;
}

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

  // int t;cin>>t;
  // while(t--)
  // {
  solve();
  // cout<<endl;
  // }

  return 0;
}