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

#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i, p, n) for (LL i = p; i < n; i++)
#define fr1(i, p, n) for (LL i = p; i >= n; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;

using namespace std;

int main() {
  LL n;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1 << endl;
  } else {
    map<int, int> mp;
    LL mod = 0;
    LL cnt = 1;
    bool f = false;
    while (1) {
      mod = mod * 10 + 7;
      mod = mod % n;
      if (mp[mod] > 0) {
        f = true;
        break;
      }
      mp[mod]++;
      if (mod == 0) {
        cout << cnt << endl;
        break;
      }
      cnt++;
    }
    if (f)
      cout << -1 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i, p, n) for (LL i = p; i < n; i++)
#define fr1(i, p, n) for (LL i = p; i >= n; i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;

using namespace std;

int main() {
  LL n;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1 << endl;
  } else {
    string t = "";
    LL mod = 0;
    LL cnt = 1;
    while (1) {
      t += "7";
      int digit = t[t.size() - 1] - '0';
      mod = mod * 10 + digit;
      mod = mod % n;
      if (mod == 0) {
        cout << cnt << endl;
        break;
      }
      cnt++;
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

// Patwari26
// #include template<t> as mine
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define endl '\\n'
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define hell 1000000007
#define INF (1ll << 60)
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define time                                                                   \\
  cerr << "\\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N = 100005;
void solve() {
  ll n;
  cin >> n;
  if (n % 2 == 0 || n % 5 == 0) {
    cout << "-1" << endl;
    return;
  }
  ll ans = 1;
  ll temp = 7;
  while (temp % n != 0) {
    temp = (temp * 10 + 7) % n;
    ans++;
  }
  cout << ans << endl;
}
signed main() {
  ios int TESTS = 1;
  // cin>>TESTS;
  while (TESTS--) {
    solve();
  }
  // time
  return 0;
}

Error: TLE

Fixed submission:

// Patwari26
// #include template<t> as mine
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define endl '\\n'
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define hell 1000000007
#define INF (1ll << 60)
#define rep(i, a, b) for (ll i = a; i <= b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)
#define ios                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define time                                                                   \\
  cerr << "\\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N = 100005;
void solve() {
  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1" << endl;
    return;
  }
  ll ans = 1;
  ll temp = 7;
  while (temp % n != 0) {
    temp = (temp * 10 + 7) % n;
    ans++;
  }
  cout << ans << endl;
}
signed main() {
  ios int TESTS = 1;
  // cin>>TESTS;
  while (TESTS--) {
    solve();
  }
  // time
  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 RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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;
}
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);

int main() {

  ll K;
  cin >> K;

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

  // vector<pair<ll, ll>> pm = prime_factorize(7777);
  // for(auto i : pm) {
  //     cout << i.first << " " << i.second << endl;

  // }
  // vector<pair<ll, ll>> pim = prime_factorize(77777);
  // for(auto i : pim) {
  //     cout << i.first << " " << i.second << endl;

  // }

  ll num = 0;
  for (int i = 1; i <= K; i++) {
    num = num * 10 + 7;
    num %= K;
    if (num == 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++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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;
}
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);

int main() {

  ll K;
  cin >> K;

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

  int cnt = 0;
  ll tmp = 7;
  while (true) {
    cnt++;
    if (tmp % K == 0) {
      cout << cnt << endl;
      return 0;
    }
    tmp = tmp * 10 + 7;
  }

  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)
typedef long long ll;
using namespace std;

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

  int k;
  cin >> k;
  bool flag = true;

  if (k % 2 == 0 || k % 5 == 0) {
    flag = false;
  }

  vector<int> x(k + 1, 0);
  double ans = 1;
  int mod = 7 % k;
  while (mod != 0 && flag) {
    int tmp = mod * 10 + 7;
    mod = tmp % k;
    ans++;
    if (x[mod] == 1) {
      flag = false;
    } else {
      x[mod] = 1;
    }
  }

  if (!flag) {
    cout << "-1" << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

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

  int k;
  cin >> k;

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

  double ans = 1;
  int mod = 7 % k;
  while (mod != 0) {
    int tmp = mod * 10 + 7;
    mod = tmp % k;
    ans++;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORB(i, m, n) for (int i = m; i >= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << #i << "= " << i << endl
using namespace std;
ll k;
ll dp[1000005];
void making(ll a, ll b) {
  ll ans = 7;
  dp[0] = 7;
  for (ll i = 1; i <= b; i++) {
    ans *= a;
    ans %= k;
    dp[i] = ans;
  }
}
int main() {

  cin >> k;
  int ans = -1;
  ll mod = 7;
  mod %= k;
  making(10, 1000001);

  for (ll i = 1; i < 1e6 + 1; i++) {
    if (mod % k == 0) {
      cout << i << endl;
      return 0;
    }

    mod += dp[i];
    mod %= k;
  }

  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORB(i, m, n) for (int i = m; i >= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << #i << "= " << i << endl
using namespace std;
ll k;
ll dp[1000000];
void making(ll a, ll b) {
  ll ans = 7;
  dp[0] = 7;
  FOR(i, 1, b) {
    ans *= a;
    ans %= k;
    dp[i] = ans;
  }
}
int main() {

  cin >> k;
  int ans = -1;
  ll mod = 7;
  mod %= k;
  making(10, 1000001);

  for (ll i = 1; i <= 1e6 + 1; i++) {
    if (mod % k == 0) {
      cout << i << endl;
      return 0;
    }

    mod += dp[i];
    mod %= k;
  }

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

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;

int main() {
  long long int n, a = 7, ans = -1;
  cin >> n;
  for (long long int i = 0; i <= n; i++) {
    if (a % n == 0) {
      ans = i + 1;
      break;
    } else {
      a = (a * 10 + 7) % n;
    }
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <vector>
using namespace std;

int main() {
  long long int n, a = 7;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1 << endl;
  } else {
    for (long long int i = 0;; i++) {
      if (a % n == 0) {
        cout << i + 1 << endl;
        break;
      } else {
        a = (a * 10 + 7) % n;
      }
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

int main() {
  int K;
  std::cin >> K;
  int m = 0;
  for (int i = 0; i < K; i++) {
    m = (m * 10 + 7 % K) % K;
    if (m == 0) {
      std::cout << i + 1 << std::endl;
      exit(0);
    }
  }
  std::cout << -1 << std::endl;
}

Error: 1

Fixed submission:

#include <iostream>

int main() {
  int K;
  std::cin >> K;
  int m = 0;
  for (int i = 0; i < K; i++) {
    m = (m * 10 + 7 % K) % K;
    if (m == 0) {
      std::cout << i + 1 << std::endl;
      exit(1);
    }
  }
  std::cout << -1 << std::endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int count(int x) {
  if (x % 2 == 0 || x % 5 == 0)
    return -1;
  int val = 7 % x;
  for (int i = 1; i < 1e7; i++) {
    if (!val)
      return i;
    val = (val * 10 + 7) % x;
  }
  return -1;
}

int main() {
  int k;
  cin >> k;
  int ans = count(k);
  cout << ans << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int getval(int x) {
  if (!(x & 1) || (x % 5 == 0))
    return -1;
  int n = 7, count = 1;
  while (n % x) {
    count++;
    n = n * 10 + 7;
  }
  return count;
}

int main() {
  int k;
  cin >> k;
  int ans = getval(k);
  cout << ans;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int K, L;
  cin >> K;
  if (K % 7 == 0)
    L = 9 * K / 7;
  else
    L = 9 * K;
  int X = 10 % L;
  int Y = 0;
  int S = 0;
  int m;
  rep(i, L) {
    if (X == 1) {
      S = 1;
      m = i;
      break;
    }
    X = (X * 10) % L;
  }
  if (S) {
    cout << m + 1 << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Error: 3

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int K;
  int X = 0;
  cin >> K;
  rep(i, K) {
    X += 7 * exp10(i);
    if (X % K == 0) {
      return i;
    }
  }
  return -1;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; } // 最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }             // 最小公倍数
using Graph = vector<vector<int>>;
ll inf = 300000000000000000;
const double PI = 3.14159265358979323846;
int main() {
  ll n;
  cin >> n;
  if (n % 2 == 0 || n % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 1;
  ll o = 7;
  while (true) {
    if (o % n == 0) {
      cout << ans << endl;
      return 0;
    }
    o = (o * 10 + 7) % n;
    ans++;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; } // 最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }             // 最小公倍数
using Graph = vector<vector<int>>;
ll inf = 300000000000000000;
const double PI = 3.14159265358979323846;
int main() {
  ll n;
  cin >> n;
  if (n % 2 == 0 || n % 5 == 0)
    cout << -1 << endl;
  int ans = 1;
  ll o = 7;
  while (true) {
    if (o % n == 0) {
      cout << ans << endl;
      return 0;
    }
    o = (o * 10 + 7) % n;
    ans++;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

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

int a[1000002];

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

  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;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  int a[100001];
  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;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long i = 0, k, n;
int main() {
  cin >> k;
  while (i < 1000000220) {
    i++;
    n = (n * 10 + 7) % k;
    if (n == 0) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  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 || k % 5 == 0) {
    cout << "-1\\n";
    return 0;
  }
  int x = 7 % k, c = 1;
  while (x != 0) {
    x = (x * 10) + 7;
    x %= k;
    c++;
  }
  cout << c << "\\n";
}

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\\n";
    return 0;
  }
  long long x = 7;
  int c = 1;
  while (x % k != 0) {
    x = (x * 10) + 7;
    c++;
  }
  cout << c << "\\n";
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
typedef long long int ll;
int main() {
  ll k;
  cin >> k;
  ll t = 0;
  ll n = 0;
  while (t < 1e7) {
    n = (n * 10 + 7) % k;
    t++;
    if (n == 0) {
      cout << t << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
typedef long long int ll;
int main() {
  ll k;
  cin >> k;
  ll n = 7;
  ll cnt = 1;
  while (n % k != 0) {
    n = n * 10 + 7;
    cnt++;
  }
  cout << cnt << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios::sync_with_stdio(false);
  long long k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << '\\n';
    return 0;
  }
  if (k % 7 == 0) {
    k /= 7;
  }
  k *= 9;
  if (k == 9) {
    cout << 1 << '\\n';
    return 0;
  }
  long long cnt = 1;
  long long hehe = 10;
  while (hehe != 1) {
    hehe *= 10;
    hehe %= k;
    cnt++;
  }
  cout << cnt << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ios::sync_with_stdio(false);
  long long k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << '\\n';
  }
  if (k % 7 == 0) {
    k /= 7;
  }
  k *= 9;
  if (k == 9) {
    cout << 1 << '\\n';
    return 0;
  }
  long long cnt = 1;
  long long hehe = 10;
  while (hehe != 1) {
    hehe *= 10;
    hehe %= k;
    cnt++;
  }
  cout << cnt << '\\n';
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  cin.sync_with_stdio(0);
long long num;
long long solve(long long mod) {
  if (mod == 0) {
    return 0;
  }
  return 1 + solve((mod * 10 + 7) % num);
}
int main() {
  cin >> num;
  if (num % 2 == 0 || num % 10 == 5) {
    printf("-1\\n");
  } else {
    cout << solve(7 % num) + 1 << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);                                                                 \\
  cin.sync_with_stdio(0);
long long num;
long long solve(long long mod) {
  if (mod == 0) {
    return 0;
  }
  return 1 + solve((mod * 10 + 7) % num);
}
int main() {
  cin >> num;
  if (num % 2 == 0) {
    printf("-1\\n");
  } else {
    cout << solve(7 % num) + 1 << 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 mod = 0;
  for (int i = 1; i <= k; i++) {
    mod *= 10;
    mod += 7;
    mod %= k;
    if (mod == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int k;
  cin >> k;
  int cnt = 1;
  long long kou = 7;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (k == 1 or k == 7) {
    cout << 1 << endl;
    return 0;
  }
  while (kou != 0) {
    kou *= 10;
    kou += 7;
    kou %= k;
    cnt++;
  }
  cout << cnt << 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 s = 7, ans = 1;
  while (ans <= k) {
    if (s % k == 0) {
      cout << ans << endl;
      return 0;
    }
    s = (s % k) * 10 + 7;
    ans++;
  }
  cout << -1 << endl;
}

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 << endl;
    return 0;
  } else {
    long long s = 7, o = 10, ans = 1;
    while (1) {
      if (s % k == 0) {
        cout << ans << endl;
        break;
      }
      s += o * 7;
      o *= 10;
      ans++;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll k;
  cin >> k;
  ll a = 7;
  ll ans = 1;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    if (a % k == 0) {
      cout << ans << endl;
      return 0;
    }
    if (ans > k) {
      cout << -1 << endl;
      return 0;
    }
    a = (a * 10 + 7) % k;
    ans++;
  }
}

Error: TLE

Fixed submission:

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

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

/**
 * author  : UshanGhosh
 * created : 2020-08-07 11:39:18
 **/

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

#define ll long long
#define pii pair<int, int>
#define vii vector<int>
#define vcc vector<char>
#define pll pair<long long, long long>
#define mem memset
#define sof sizeof
#define co1 __builtin_popcountll
#define PB push_back
#define UB upper_bound
#define LB lower_bound
#define MP make_pair
#define TS to_string
#define F first
#define S second
#define endl '\\n'

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long a, b, c, d, e, f, i = 0, j, k, m, n, o, x, y;
  cin >> n;
  if (__gcd(n, (ll)10) != 1) {
    cout << -1 << "\\n";
    return 0;
  }
  ll v = 0;
  while (1) {
    i++;
    v = (v * 10 + 7) % n;
    if (v == 0) {
      cout << i;
      break;
    }
  }
}

Error: TLE

Fixed submission:

/**
 * author  : UshanGhosh
 * created : 2020-08-07 11:35:51
 **/

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

#define ll long long
#define pii pair<int, int>
#define vii vector<int>
#define vcc vector<char>
#define pll pair<long long, long long>
#define mem memset
#define sof sizeof
#define co1 __builtin_popcountll
#define PB push_back
#define UB upper_bound
#define LB lower_bound
#define MP make_pair
#define TS to_string
#define F first
#define S second
#define endl '\\n'

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long a, b, c, d, e, f, i = 0, j, k, m, n, o, x, y;
  cin >> n;
  if (__gcd(n, (ll)10) != 1) {
    cout << -1 << "\\n";
    return 0;
  }
  ll v = 0;
  while (1) {
    i++;
    v = v * 10 + 7;
    if (v % n == 0) {
      cout << i;
      break;
    }
  }
}