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

#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll k;
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % (k * 9);
    }
    x = x * x % (k * 9);
    n >>= 1;
  }
  return res;
}
int main() {
  cin >> k;
  for (int i = 1; i <= k; i++) {
    // cout << i << endl;
    if (7 * ((mod_pow(10, i) - 1)) % (9 * k) == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
ll k;
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % (k * 9);
    }
    x = x * x % (k * 9);
    n >>= 1;
  }
  return res;
}
int main() {
  cin >> k;
  for (int i = 1; i <= 9 * k; i++) {
    // cout << i << endl;
    if (7 * ((mod_pow(10, i) - 1)) % (9 * k) == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {

  long long k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << "-1\\n";
  } else {
    long long p = 7 % k;
    int cnt = 1;
    while (p != 0) {
      p = (p * 10 + 7) % k;
      ++cnt;
    }

    cout << cnt << "\\n";
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int seq = 7, num = 1, result = -1;
  int k;
  cin >> k;
  if (k & 1) {
    result = 0;
    while (!((seq * num) % k == 0)) {
      num = num * 10 + 1;
      result++;
    }
    cout << result + 1;
  } else
    cout << -1;
  return (0);
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #pragma GCC optimize ("-O3")

using namespace std;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// const long double PI = 3.14159265358979323846;  /* pi */

int main() {
  // ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int k;
  cin >> k;
  vector<bool> visited(k, false);
  int val = 0;
  int ans = 0;
  for (int i = 0; i < 1e6; i++) {
    ans++;
    val = val * 10 + 7;
    val = val % k;
    int rem = val % k;
    if (visited[rem])
      break;
    visited[rem] = true;
    if (rem == 0)
      break;
  }
  if (visited[0])
    cout << ans << "\\n";
  else
    cout << -1 << "\\n";
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
// #pragma GCC optimize ("-O3")

using namespace std;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// const long double PI = 3.14159265358979323846;  /* pi */

int main() {
  // ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int k;
  cin >> k;
  vector<bool> visited(k, false);
  int val = 0;
  int ans = 0;
  for (int i = 0; i < 1e6; i++) {
    ans++;
    val = val * 10 + 7;
    int rem = val % k;
    if (visited[rem])
      break;
    visited[rem] = true;
    if (rem == 0)
      break;
  }
  if (visited[0])
    cout << ans << "\\n";
  else
    cout << -1 << "\\n";
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int ans = 1;
  int K;
  cin >> K;
  if (K % 2 == 0)
    cout << -1 << endl;
  else {
    vector<int> L(K, 0);
    int m = 7 % K;
    int n = m;
    L[n] = 1;
    while (n != 0) {
      m = (m * 10) % K;
      n = (n + m) % K;
      ans++;
      if (L[n] == 1) {
        cout << -1 << endl;
        return 0;
      } else
        L[n] = 1;
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

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


/*

 Remember, Hope is a good thing... May be the best of things... And No Good
 thing ever Dies !!!

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cout.tie(0);
#define endl "\\n"
#define MOD 1000000007
const ll inf = (1LL << 60) - 1;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
ll stringtonum(string s) {
  ll d = 0;
  for (ll i = 0; i < s.size(); i++) {
    d = d * 10 + (s[i] - '0');
  }
  return d;
}
void solve() {
  ll n, c = 0;
  cin >> n;
  if (!(n & 1) || n % 5 == 0)
    cout << -1 << endl;
  else {
    ll x = 7;
    while (1) {
      if (x % n == 0) {
        cout << c + 1 << endl;
        // cout<<x<<endl;
        break;
      }
      x = (x % n) * 10 + 7;
      c++;
      // cout<<x<<endl;
      // s.push_back('7');
    }
  }
}
int main() {
  IOS;
  // ll t;
  // cin>>t;
  // while(t--)
  solve();
  return 0;
}


Error: TLE

Fixed submission:


/*

 Remember, Hope is a good thing... May be the best of things... And No Good
 thing ever Dies !!!

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cout.tie(0);
#define endl "\\n"
#define MOD 1000000007
const ll inf = (1LL << 60) - 1;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
ll stringtonum(string s) {
  ll d = 0;
  for (ll i = 0; i < s.size(); i++) {
    d = d * 10 + (s[i] - '0');
  }
  return d;
}
void solve() {
  ll n, c = 0;
  cin >> n;
  if (!(n & 1))
    cout << -1 << endl;
  else {
    ll x = 7;
    string s;
    s.push_back('7');
    while (1) {
      if (x % n == 0) {
        cout << c + 1 << endl;
        // cout<<x<<endl;
        break;
      }
      x = (x % n) * 10 + 7;
      c++;
      // cout<<x<<endl;
      s.push_back('7');
    }
  }
}
int main() {
  IOS;
  // ll t;
  // cin>>t;
  // while(t--)
  solve();
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
map<int, int> mm;
int main() {
  int flag = 0;
  int num = 1;
  int n;
  int a = 7;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (a % n != 0) {
    a = (a * 10 + 7) % n;
    if (!mm[a])
      mm[a]++;
    else {
      flag = 1;
      break;
    }
    num++;
  }
  if (flag) {
    cout << -1 << endl;
  } else
    cout << num << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

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

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

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define all(x) (x).begin(), (x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

const int mod = 1e9 + 7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve() {
  ll k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0)
    cout << -1 << '\\n';
  else {
    int cnt = 1;
    ll val = 7;
    while (val % k) {
      val = val * 10 % k;
      val = (val + 7) % k;
      cnt++;
    }
    cout << cnt << '\\n';
  }
}

int main() {
  IOS int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}


Error: TLE

Fixed submission:

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

#define IOS                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define all(x) (x).begin(), (x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

const int mod = 1e9 + 7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve() {
  ll k;
  cin >> k;
  if (k % 2 == 0)
    cout << -1 << '\\n';
  else {
    int cnt = 1;
    ll val = 7;
    while (val % k) {
      val = val * 10 % k;
      val = (val + 7) % k;
      cnt++;
    }
    cout << cnt << '\\n';
  }
}

int main() {
  IOS int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)(n); ++i)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ll k;
  cin >> k;
  vector<ll> num(k, 0);

  if (k % 2 == 0) {
    cout << "-1\\n";
    return 0;
  }
  ll i = 1;
  ll x = 7;
  num[x % k] = 1;

  while (x % k != 0) {
    x = 10 * x + 7;
    x %= k;
    if (num[x]) {
      cout << "-1\\n";
      return 0;
    } else {
      num[x] = 1;
    }
    i++;
  }

  cout << i << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)(n); ++i)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

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

  while (x % k != 0) {
    x = 10 * x + 7;
    x %= k;
    i++;
  }

  cout << i << endl;

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

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

int main() {
  int k;
  scanf("%d", &k);
  if (k % 2 == 0 || k % 5 == 0) {
    printf("-1");
  } else {
    ll cnt = 0, sum = 0;
    while (true) {
      cnt++;
      sum = sum * 10 + 7;
      if (sum % k == 0) {
        break;
      } else
        sum %= k;
    }
    printf("%lld", cnt);
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  int k;
  scanf("%d", &k);
  if (k % 2 == 0) {
    printf("-1");
  } else {
    ll cnt = 0, sum = 0;
    while (true) {
      cnt++;
      sum = sum * 10 + 7;
      if (sum % k == 0) {
        break;
      } else
        sum %= k;
    }
    printf("%lld", cnt);
  }
  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 x = 7 % k;
  for (int i = 1; i <= k; i++) {
    if (x == 0) {
      cout << i << endl;
      return 0;
    }
    x = (x * 10 + 7) % k;
  }
  cout << -1 << endl;
  return 0;
  /*
  if(k % 2 == 0){
    cout << -1 << endl;
    return 0;
  }
  int n=7,count=1;
  while(1){
    if(n % k == 0){
      cout << count << endl;
      return 0;
    }else{
      n = (n*10 + 7 )% k;
      count++;
    }
  */
}


Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>
#define ll long long int
using namespace std;

int main() {
  int k;
  cin >> k;
  ll val = 7;
  int count = 0;
  bool temp = true;
  if (k % 2 == 0) {
    cout << -1 << endl;
  } else {
    while (true) {
      if (val % k == 0) {
        count++;
        break;
      } else if (count > k) {
        temp = false;
        break;
      } else {
        val = (val % k) * 10 + 7;
        count++;
      }
    }
    if (temp) {
      cout << count << endl;
    } else {
      cout << -1 << endl;
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
using namespace std;

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

#include <bits/stdc++.h>

int main() {
  using namespace std;
  unsigned long K;
  cin >> K;
  unsigned long T{7}, ans{1}, pt{0};
  while (T % K) {
    ++ans;
    if (ans > 2 * K)
      return 0 & puts("-1");
    ((T *= 10) += 7) %= K;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

int main() {
  using namespace std;
  unsigned long K;
  cin >> K;
  if (K == 2 || K == 5 || K == 10)
    return 0 & puts("-1");
  unsigned long T{7}, ans{1};
  while (T % K) {
    ++ans;
    ((T *= 10) += 7) %= K;
  }
  cout << ans << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
#define ll long long
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll k;
  cin >> k;
  ll seven = 7 % k;
  int ans = -1;
  for (int i = 1; i < 1e7; i++) {
    if (seven == 0) {
      ans = i;
      break;
    }
    seven = (seven * 10 + 7) % k;
  }
  cout << ans << '\\n';
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
#define ll long long
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll k;
  cin >> k;
  int seven = 7;
  int ans = -1;
  if (k % 2 != 0) {
    ans = 1;
    while (seven % k != 0) {
      int extra = seven * 10;
      seven = 7 + extra;
      ans++;
    }
  }
  cout << ans << '\\n';
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  set<int> s;
  int bn = 7 % K; // define (an % 7) as bn

  int cnt = 1;
  while (s.count(bn) == 0) {
    if (bn == 0) {
      cout << cnt << endl;
      return 0;
    }
    s.insert(bn);
    bn = (10 * bn + 7) % K;
    cnt++;
  }

  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

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

  int count = log10(K);
  long long arraySeven = 0;

  for (int i = 0; i < count; i++)
    arraySeven = arraySeven * 10 + 7;
  while (1) {
    count++;
    arraySeven = arraySeven * 10 + 7;

    if (arraySeven % K == 0) {
      cout << count;
      break;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  ll sum = 1;
  int a = 7 % k;
  int tmp = a;
  bool flg = true;
  while (a) {
    a = 10 * a + 7;
    a %= k;
    if (sum > k) {
      flg = false;
      break;
    }
    sum++;
  }
  if (flg) {
    cout << sum << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

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

  ll sum = 1;
  int a = 7 % k;
  int tmp = a;
  bool flg = true;
  while (a) {
    a = 10 * a + 7;
    a %= k;
    if (tmp == a) {
      flg = false;
      break;
    }
    sum++;
  }
  if (flg) {
    cout << sum << endl;
  } else {
    cout << -1 << endl;
  }

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

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

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

  // freopen("input.txt","r",stdin);

  long long n, i = 1, k = 7;
  cin >> n;
  while (1) {
    if (n % 2 == 0 || n % 5 == 0) {
      cout << -1 << endl;
      break;
    } else {
      if (k % n) {
        k = 10 * (k % n) + 7;
      } else {
        cout << i << endl;
        break;
      }
      i++;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

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

  // freopen("input.txt","r",stdin);

  long long n, i = 1, k = 7;
  cin >> n;
  while (1) {
    if (n % 2 == 0) {
      cout << -1 << endl;
      break;
    } else {
      if (k % n) {
        k = 10 * (k % n) + 7;
      } else {
        cout << i << endl;
        break;
      }
      i++;
    }
  }

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

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  int cnt = 1;
  int target = 7 % k;
  while (cnt <= k) {
    if (target == 0) {
      cout << cnt << endl;
      return 0;
    }
    target = (target * 10 + 7) % k;
    cnt++;
  }
  cout << -1 << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  int cnt = 1, n = 2;
  int target = 7;
  while (target % k != 0) {
    target = target * 10 + 7;
    n++;
    cnt++;
  }
  cout << cnt << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
// const int N = ;
int k;
int main() {
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0)
    puts("-1");
  else {
    int x = 7, ans = 1;
    x %= k;
    while (x != 0) {
      x = (x * 10 + 7) % k;
      ans++;
    }
    cout << ans;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>
#include <iostream>
#define int long long int
#define vi vector<int>
#define vvi vector<vector<int>>
using namespace std;

int32_t main() {
  // your code goes here
  int k, count = 0, sum = 0, i, j;
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1\\n";
  } else {
    while (1) {
      if (count > k) {
        cout << "-1\\n";
        break;
      }
      sum = 10 * sum + 7;
      count++;
      sum %= k;
      if (!sum) {
        cout << count << "\\n";
        break;
      }
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#define int long long int
#define vi vector<int>
#define vvi vector<vector<int>>
using namespace std;

int32_t main() {
  // your code goes here
  int k, count = 0, sum = 0, i, j;
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1\\n";
  } else {
    while (1) {
      sum = 10 * sum + 7;
      count++;
      sum %= k;
      if (!sum) {
        cout << count << "\\n";
        break;
      }
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

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

  int count = 1;
  int mod = 7;
  int now = 7;
  std::unordered_set<int> s;
  while (true) {
    mod %= K;
    if (s.count(mod) > 0) {
      cout << "-1" << endl;
      break;
    }
    s.insert(mod);
    if (mod == 0) {
      cout << count << endl;
      break;
    }
    now = (now * 10) % K;
    mod += now;
    if (now == 0) {
      cout << "-1" << endl;
      break;
    }
    count++;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

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

  int count = 1;
  int mod = 7;
  int now = 7;
  while (true) {
    mod %= K;
    if (mod == 0) {
      cout << count << endl;
      break;
    }
    now = (now * 10) % K;
    mod += now;
    if (now == 0) {
      cout << "-1" << endl;
      break;
    }

    count++;
  }

  return 0;
}