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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define ii pair<int, int>
#define lp(x, y) for (ll i = x; i < y; i++)
#define pb push_back
const int N = 200 * 1000 + 11;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll k, count = 0;
  cin >> k;
  ll a = 7, t = 1, check = 0;
  if (k % 2 == 0)
    cout << "-1";
  else {
    while (t) {
      check++;
      if (a < k) {
        a = a * 10 + 7;
        count++;
      } else {
        if (a % k == 0) {
          count++;
          break;
        } else {
          ll q = a / k;
          ll p = k * q;
          ll t = a - p;
          a = t * 10 + 7;

          count++;
        }
      }
      if (check == 99999999) {
        count = -1;
        break;
      }
    }
    cout << count;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define ii pair<int, int>
#define lp(x, y) for (ll i = x; i < y; i++)
#define pb push_back
const int N = 200 * 1000 + 11;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll k, count = 0;
  cin >> k;
  ll a = 7, t = 1, check = 0;
  if (k % 2 == 0)
    cout << "-1";
  else {
    while (t) {
      if (a < k) {
        a = a * 10 + 7;
        count++;
      } else {
        if (a % k == 0) {
          count++;
          break;
        } else {
          ll q = a / k;
          ll p = k * q;
          ll t = a - p;
          a = t * 10 + 7;
          if (check == a) {
            count = -1;
            break;
          } else {
            check = a;
            count++;
          }
        }
      }
    }
    cout << count;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int K;
  cin >> K;
  int x = 7 % K;
  set<int> s;
  int i = 1;
  while (s.count(x) == 0) {
    if (x == 0) {
      cout << i << endl;
      return 0;
    }
    s.insert(x);
    x = (x * 10 + 7) % K;
    i++;
  }

  cout << -1 << endl;

  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  long long K;
  cin >> K;
  string a;
  if (K % 2 == 0)
    cout << -1;
  else {
    bool flag = false;
    a = to_string(K);
    string b = "";
    for (long long i = 1; i < a.length(); i++) {
      b = b + "7";
    }
    for (long long i = 1; i < K; i++) {
      if (stoi(b) % K == 0) {
        flag = true;
        break;
      }
      b = b + "7";
    }
    if (flag == true)
      cout << b.length();
    else
      cout << -1;
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
inline ll Pow(ll A, ll B, ll M) {
  ll Y = 1;
  while (B > 0) {
    if (B & 1)
      Y = Y * A % M;
    A = A * A % M;
    B >>= 1;
  }
  return Y;
}

ll M = 1;

int Process() {
  if (M % 2 == 0)
    return -1;
  int ans = 1;
  ll n = 7 % M, expo = 1;
  vector<bool> vis(M, 0);
  while (n) {
    n = (n + (7 * Pow(10, expo, M))) % M;
    ans++;
    expo++;
    if (vis[n])
      return -1;
    vis[n] = 1;
  }
  return ans;
}

void Output() { cout << Process() << "\\n"; }

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

  while (cin >> M)
    Output();

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
inline ll Pow(ll A, ll B, ll M) {
  ll Y = 1;
  while (B > 0) {
    if (B & 1)
      Y = Y * A % M;
    A = A * A % M;
    B >>= 1;
  }
  return Y;
}

ll M = 1;

int Process() {
  if (M % 2 == 0)
    return -1;
  int ans = 1;
  ll n = 7 % M, expo = 1;
  while (n) {
    n = (n + (7 * Pow(10, expo, M))) % M;
    ans++;
    expo++;
  }
  return ans;
}

void Output() { cout << Process() << "\\n"; }

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

  while (cin >> M)
    Output();

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

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; // 最大値

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main() {
  ll n;
  cin >> n;
  ll res = 7 % n, cnt = 1;

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

  while (res != 0) {
    cnt++;
    res = res * 10 + 7;
    res %= n;
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 0; // 最大値

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define PB push_back
#define F first
#define S second

int main() {
  ll n;
  cin >> n;
  ll res = 7 % n, cnt = 1;
  while (res != 0) {
    cnt++;
    res = res * 10 + 7;
    res %= n;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\\n'
#define vec vector<ll>
#define mat vector<vector<ll>>
#define fi first
#define se second
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 998244353;
signed main() {
  ll k;
  cin >> k;
  ll ans = -1;
  vector<ll> a(k + 1);
  a[0] = 7 % k;
  rep(i, k + 1) {
    if (a[i] % k == 0) {
      ans = i + 1;
      break;
    }
    if (i < k)
      a[i + 1] = (a[i] * 10 + 7) % k;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\\n'
#define vec vector<ll>
#define mat vector<vector<ll>>
#define fi first
#define se second
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 998244353;
signed main() {
  ll k;
  cin >> k;
  ll ans = -1;
  vector<ll> a(k + 1);
  a[0] = 7 % k;
  rep(i, k + 1) {
    if (a[i] % k == 0) {
      ans = i + 1;
      break;
    }
    if (i < k + 1)
      a[i + 1] = (a[i] * 10 + 7) % k;
  }
  cout << ans << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

int main() {
  int K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (K % 7 == 0) {
    K /= 7;
  }
  ll x = 1;
  int ans = 0;
  while (x % K != 0 && ans < 10000000) {
    ans++;
    x = 10 * x + 1;
    x %= K;
  }
  if (ans == 10000000) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans + 1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

int main() {
  int K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (K % 7 == 0) {
    K /= 7;
  }
  ll x = 1;
  int ans = 0;
  while (x % K != 0) {
    ans++;
    x = 10 * x + 1;
    x %= K;
  }
  cout << ans + 1 << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

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

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

  ll n, d, cnt = 1;
  set<ll> s;
  cin >> n;
  ll aux = 1;
  if (n % 7 == 0)
    n /= 7;

  while (1) {
    if (s.find(aux) != s.end()) {
      cout << "-1";
      return 0;
    }

    if (aux % n == 0)
      break;

    s.insert(aux);
    cnt++;
    aux %= n;
    aux = aux * 10 + 1;
  }
  cout << cnt;
}

Error: WA

Fixed submission:

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

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

  ll n, d, cnt = 1;
  set<ll> s;
  cin >> n;
  ll aux = 1;
  if (n % 7 == 0)
    n %= 7;
  while (1) {
    if (s.find(aux) != s.end()) {
      cout << "-1";
      return 0;
    }

    if (aux % n == 0)
      break;

    s.insert(aux);
    cnt++;
    aux %= n;
    aux = aux * 10 + 1;
  }
  cout << cnt;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  long long k, x;
  cin >> k;

  x = 7 % k;

  for (int i = 1; i <= k; i++) {
    if (x == 0) {
      cout << i;
      return 0;
    }
    x = (x * 10 + 7) % k;
  }

  cout << "-1";

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <cstdio>

using namespace std;

bool is_even(int num) { return num % 2 == 0; }

bool is_multiplied_by_k(int num, int k) { return num % k == 0; }

int main() {
  int k;
  int count = 0;
  string num_str = "7";

  cin >> k;

  if (is_even(k)) {
    cout << "-1" << endl;
  } else {
    bool found = false;
    while (!found) {
      if (is_multiplied_by_k(stoi(num_str), k)) {
        found = true;
      } else {
        num_str = num_str + '7';
      }
      count++;
    }
  }
  cout << count << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rept(i, k, n) for (long long i = (k); i < (long long)(n); i++)
#define All(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(), v.end())
#define Rsort(v) sort(v.begin(), v.end(), [](auto a, auto b) { return a > b; })
#define Reverse(v) reverse(v.begin(), v.end())
#define MAX 1000000007
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<long long, long long> Pll;
typedef tuple<int, int, int> Tii;

template <typename T> ostream &operator<<(ostream &s, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    if (i)
      s << ',';
    else
      s << '{';
    s << setw(2) << vec[i];
  }
  s << '}' << endl;
  return s;
}

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

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rept(i, k, n) for (long long i = (k); i < (long long)(n); i++)
#define All(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(), v.end())
#define Rsort(v) sort(v.begin(), v.end(), [](auto a, auto b) { return a > b; })
#define Reverse(v) reverse(v.begin(), v.end())
#define MAX 1000000007
typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<long long, long long> Pll;
typedef tuple<int, int, int> Tii;

template <typename T> ostream &operator<<(ostream &s, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    if (i)
      s << ',';
    else
      s << '{';
    s << setw(2) << vec[i];
  }
  s << '}' << endl;
  return s;
}

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

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int, int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const int z = 1000000007;
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
int main() {
  int k;
  cin >> k;
  int modk7 = 7 % k;
  int mod_k = 7 % k;
  int ans = 1;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    if (ans > 10000000) {
      ans = -1;
      break;
    }
    if (mod_k == 0)
      break;
    mod_k = (mod_k * 10 + modk7) % k;
    ans++;
  }
  cout << ans << endl;
  ;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int, int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const int z = 1000000007;
long long GCD(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
int main() {
  int k;
  cin >> k;
  int modk7 = 7 % k;
  int mod_k = 7 % k;
  int ans = 1;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    if (mod_k == 0)
      break;
    mod_k = (mod_k * 10 + modk7) % k;
    ans++;
  }
  cout << ans << endl;
  ;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int K;
  cin >> K;
  int C = 1;
  int M = 7;
  if (M % K == 0) {
    cout << 1;
  } else if (K % 2 == 0 || K % 5 == 0) {
    cout << -1;
  } else {
    M = 77 % K;
    C = 2;
    while (M != 0 && M != (7 % K)) {
      C += 1;
      M = (M * 10 + 7) % K;
    }
    if (M == 0) {
      cout << C;
    } else {
      cout << -1;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

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

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll N = pow(10, 9);

int main() {
  int k;
  cin >> k;
  set<int> s;
  int x = 7 % k;
  int i = 1;
  while (s.count(x) == 0) {
    if (x == 0) {
      cout << i << endl;
      return 0;
    }
    s.insert(x);
    x = (x * 10 + 7) % k;
    i++;
  }
  cout << -1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll N = pow(10, 9);

int main() {
  ll k;
  cin >> k;
  ll j = 7;
  ll cnt = 0;
  if (k % 2 == 0) {
    cout << -1;
    cnt++;
  }
  if (j % k == 0) {
    cout << 1;
    cnt++;
  }
  if (cnt == 0) {
    for (int i = 1; i < N; i++) {
      j += 7 * pow(10, i);
      if (j % k == 0) {
        cout << i + 1;
        cnt++;
        break;
      }
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using pll = pair<long long, long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using pll = pair<long long, long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

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

#include <iostream>
using namespace std;

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int n = 0;
  int k1 = k;
  int num = 0;
  int des = 1;
  while (k1) {
    n++;
    num = 7 * des + num;
    des *= 10;
    k1 /= 10;
  }
  // cout<<des<<endl;
  int count = 0;
  while (1) {
    num = num % k;
    if (num == 0) {

      // cout<<num<<endl;
      cout << n << endl;
      return 0;
    } else {

      n++;

      num = num * 10 + 7;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int n = 0;
  int k1 = k;
  int num = 0;
  int des = 1;
  while (k1) {
    n++;
    num = 7 * des + num;
    des *= 10;
    k1 /= 10;
  }
  // cout<<des<<endl;
  int count = 0;
  while (1) {
    num = num % k;
    if (num == 0) {

      // cout<<num<<endl;
      cout << n << endl;
      return 0;
    } else {

      n++;

      num = num * 10 + 7;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  int64_t L, s = 1;
  if (n % 2 == 0 || n % 5 == 0) {
    cout << -1 << endl;
  } else if (n % 7 == 0) {
    L = 9 * n / 7;
    s = 10 % L;
    for (int64_t i = 1;; i++) {
      if (s % L == 1) {
        cout << i << endl;
        break;
      }
      s = (s % L) * 10;
    }
  } else {
    L = 9 * n;
    s = 10 % L;
    for (int64_t i = 1;; i++) {
      if (s % L == 1) {
        cout << i << endl;
        break;
      }
      s = (s % L) * 10;
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n;
  cin >> n;
  int64_t L, s = 1;
  if (n % 7 == 0) {
    L = 9 * n / 7;
    s = 10 % L;
    for (int64_t i = 1;; i++) {
      if (s % L == 1) {
        cout << i << endl;
        break;
      }
      s = (s % L) * 10;
    }
  } else {
    L = 9 * n;
    s = 10 % L;
    for (int64_t i = 1;; i++) {
      if (s % L == 1) {
        cout << i << endl;
        break;
      }
      s = (s % L) * 10;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll K, val;

int main() {

  ios_base::sync_with_stdio(false);
  cin >> K;
  val = 7;
  for (int i = 1; i <= 10000000; i++) {
    if (val % K == 0) {
      cout << i;
      return 0;
    }
    val = val * 10 + 7;
    val %= K;
  }
  cout << "-1";
}

Error: TLE

Fixed submission:

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

int main() {
  long long n, l = 0, ans = 0;
  cin >> n;
  if (n % 2 == 0)
    cout << "-1\\n";
  else {
    do {
      l *= 10;
      l += 7;
      l %= n;
      ans++;
    } while (l != 0);
    cout << ans << '\\n';
  }
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 233;

int a[maxn];
int main() {
  int k;
  cin >> k;
  int flag = 0;
  a[1] = 7 % k;
  for (int i = 2; i <= k; i++) {
    a[i] = (a[i - 1] * 10 + 7) % k;
  }
  for (int i = 1; i <= k; i++) {
    if (a[i] == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 233;

int a[maxn];
int main() {
  int k;
  cin >> k;
  int flag = 0;
  a[1] = 7 % k;
  for (int i = 2; i <= k; i++) {
    a[i] = (a[i - 1] * 10 + 7) % k;
  }

  for (int i = 1; i <= k; i++) {
    if (a[i] == 0) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}