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

#include <bits/stdc++.h>

using namespace std;

#define PI (3.14159265358979323846)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define MS multiset
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int, int>>
#define VLL vector<ll>
#define SZ(x) ((int)x.size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

const db eps = 0.00001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 750555;
const int M = 1125;

ll powmod(ll n, ll k, ll m) {
  if (k == 0)
    return 1;
  ll x = powmod(n, k / 2, m) % m;
  x = x * x % m;
  if (k % 2)
    x = x * n % m;
  return x % m;
}

void solve() {
  int k;
  cin >> k;

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

  cout << -1;
}

int main() {
  ios_base::sync_with_stdio(false);

#ifdef dxz05
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#else

#endif

  int T = 1;
  // cin >> T;

  while (T--) {
    solve();
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define PI (3.14159265358979323846)
#define MP make_pair
#define n1 first
#define n2 second
#define ALL(x) (x).begin(), (x).end()
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define MS multiset
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int, int>>
#define VLL vector<ll>
#define SZ(x) ((int)x.size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

const db eps = 0.00001;
const int INF = 1000000007;
const ll LINF = 1000000000000000555;
const int N = 750555;
const int M = 1125;

ll powmod(ll n, ll k, ll m) {
  if (k == 0)
    return 1;
  ll x = powmod(n, k / 2, m) % m;
  x = x * x % m;
  if (k % 2)
    x = x * n % m;
  return x % m;
}

void solve() {
  ll k;
  cin >> k;

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

  cout << -1;
}

int main() {
  ios_base::sync_with_stdio(false);

#ifdef dxz05
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#else

#endif

  int T = 1;
  // cin >> T;

  while (T--) {
    solve();
  }

  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 << endl;
  } else {
    if (K % 7 == 0) {
      K /= 7;
    }
    int mod = 9 * K;
    int x = 1 % (9 * K);
    for (int i = 1;; i++) {
      x = (x * (10 % mod)) % mod;
      if (x == 1) {
        cout << i << endl;
        return 0;
      }
    }
  }
  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 << endl;
  } else {
    if (K % 7 == 0) {
      K /= 7;
    }
    int mod = 9 * K;
    int x = 1 % 9 * K;
    for (int i = 1;; i++) {
      x = (x * (10 % mod)) % mod;
      if (x == 1) {
        cout << i << endl;
        return 0;
      }
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for (ll i = 0; i < n; i++)

#ifdef DEBUG
#define DBG(fmt, ...) fprintf(stderr, fmt "\\n", ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

int main() {
  std::cout << std::fixed << std::setprecision(10);

  ll K;

  cin >> K;

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

  ll i = 1;
  ll m = 7;

  unordered_set<ll> seen;
  seen.insert(m);

  while (true) {
    if (m % K == 0) {
      break;
    }
    m = m % K;
    m = m * 10 + 7;
    if (seen.find(m) != seen.end()) {
      cout << -1 << endl;
      return 0;
    }
    seen.insert(m);
    i++;
  }

  cout << i << endl;
}


Error: TLE

Fixed submission:

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for (ll i = 0; i < n; i++)

#ifdef DEBUG
#define DBG(fmt, ...) fprintf(stderr, fmt "\\n", ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

int main() {
  std::cout << std::fixed << std::setprecision(10);

  ll K;

  cin >> K;

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

  ll i = 1;
  ll m = 7;

  while (true) {
    if (m % K == 0) {
      break;
    }
    m = m % K;
    m = m * 10 + 7;
    i++;
  }

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

#include <bits/stdc++.h>

using namespace std;

int32_t main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0);

  long long k;

  cin >> k;

  long long cur = 0;

  long long mul = 1;

  for (long long i = 0; i < 1e7; i++) {

    cur += ((7 * mul) % k);

    cur %= k;

    if (cur == 0) {

      cout << i + 1 << '\\n';

      return 0;
    }

    mul *= 10;

    mul %= k;
  }

  cout << -1 << '\\n';

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

long long power(long long a, long long b, long long mod = LLONG_MAX) {

  long long res = 1;

  while (b > 0) {

    if (b & 1)

      res = (res * a) % mod;

    a = (a * a) % mod;

    b >>= 1;
  }

  return res;
}

int32_t main() {

  ios_base::sync_with_stdio(false);

  cin.tie(0);

  long long k;

  cin >> k;

  long long cur = 0;

  for (long long i = 0; i < 1e7; i++) {

    cur += ((7 * power(10, i, k)) % k);

    cur %= k;

    if (cur == 0) {

      cout << i + 1 << '\\n';

      return 0;
    }
  }

  cout << -1 << '\\n';

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

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

#define Rep(i, a, b) for (int i = a; i <= b; i++)
#define _Rep(i, a, b) for (int i = a; i >= b; i--)
#define RepG(i, u) for (int i = head[u]; ~i; i = e[i].next)

typedef long long ll;

const int N = 1e5 + 5;

template <typename T> void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 1) + (x << 3) + c - '0';
  x *= f;
}

int n;

int main() {
  read(n);
  if (n % 2 == 0)
    return puts("-1"), 0;
  int k = 0, ans = 0;
  while (1) {
    k = k * 10 + 7, k %= n;
    ans++;
    if (!k)
      break;
    if (ans > 5e7)
      return puts("-1"), 0;
  }
  printf("%d\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

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

#define Rep(i, a, b) for (int i = a; i <= b; i++)
#define _Rep(i, a, b) for (int i = a; i >= b; i--)
#define RepG(i, u) for (int i = head[u]; ~i; i = e[i].next)

typedef long long ll;

const int N = 1e5 + 5;

template <typename T> void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 1) + (x << 3) + c - '0';
  x *= f;
}

int n;

int main() {
  read(n);
  if (n % 2 == 0)
    return puts("-1"), 0;
  int k = 0, ans = 0;
  while (1) {
    k = k * 10 + 7, k %= n;
    ans++;
    if (!k)
      break;
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define f0(i, a, n) for (i = a; i < n; i++)
#define f1(i, a, n) for (i = a; i <= n; i++)
#define tc(t)                                                                  \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define ini(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define ll long long int
#define vi vector<int>
#define si set<int>
#define pb push_back
#define mp make_pair
#define M 1e9 + 7
#define rr return 0
#define endl '\\n'

using namespace std;

void solve() {
  ll k, r = 0, cnt = 0;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
  } else {
    do {
      r = ((r * 10) + 7) % k;
      cnt++;
    } while (r != 0);
    cout << cnt << endl;
  }
}

int main() {
  IOS;
  solve();
  rr;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define f0(i, a, n) for (i = a; i < n; i++)
#define f1(i, a, n) for (i = a; i <= n; i++)
#define tc(t)                                                                  \\
  int t;                                                                       \\
  cin >> t;                                                                    \\
  while (t--)
#define ini(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define ll long long int
#define vi vector<int>
#define si set<int>
#define pb push_back
#define mp make_pair
#define M 1e9 + 7
#define rr return 0
#define endl '\\n'

using namespace std;

void solve() {
  ll k, r = 0, cnt = 0;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
  } else {
    do {
      r = ((r * 10) + 7) % k;
      cnt++;
    } while (r != 0);
    cout << cnt << endl;
  }
}

int main() {
  IOS;
  solve();
  rr;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define fastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
typedef long long ll;
typedef long double ld;

const ll MOD = 1E9 + 7, INF = 2E18 + 5;
const double PI = 2 * acos(0.0);
const long double EPS = 1.0E-14;

int main() {
  ll n, ans = 1, val = 7, rem, ex, flag = 0;
  cin >> n;
  if (n % 2 == 0)
    cout << "-1";
  else {
    while (val % n != 0) {
      rem = val % n;
      val = (rem * 10) + 7;
      ans++;
      if (ans > 1E7) {
        flag = 1;
        break;
      }
    }
    if (flag)
      cout << -1;
    else
      cout << ans;
  }

  return 0;
}


Error: TLE

Fixed submission:

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

#define fastIO                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
typedef long long ll;
typedef long double ld;

const ll MOD = 1E9 + 7, INF = 2E18 + 5;
const double PI = 2 * acos(0.0);
const long double EPS = 1.0E-14;

int main() {
  ll n, ans = 1, val = 7, rem, ex;
  cin >> n;
  if (n % 2 == 0)
    cout << "-1";
  else {
    while (val % n != 0) {
      rem = val % n;
      val = (rem * 10) + 7;
      ans++;
    }
    cout << ans;
  }

  return 0;
}
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)
#define REP(i, a, b) for (int i = int(a); i < (int)b; ++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll, ll>>
#define pb push_back

using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ll k, ans = 0, num = 7;
  cin >> k;
  vector<ll> a;
  ll index = 1;
  bool flag = true;
  if (num % k == 0) {
    cout << 1 << endl;
    return 0;
  }
  rep(i, k) {
    if (num == 0) {
      flag = false;
      break;
    }
    a.pb(num);
    num = (num * 10 + 7) % k;
    index++;
  }
  if (flag) {
    cout << -1 << endl;
  } else {
    cout << index << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = int(a); i < (int)b; ++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll, ll>>
#define pb push_back

using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(void) {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ll k, ans = 0, num = 7;
  cin >> k;
  vector<ll> a;
  ll index = 1;
  bool flag = true;
  if (num % k == 0) {
    cout << 1 << endl;
    return 0;
  }
  while (1) {
    if (num == 0)
      break;
    if (find(a.begin(), a.end(), num) != a.end()) {
      flag = false;
      break;
    }
    a.pb(num);
    if (index == 999982) {
      cerr << num << endl;
    }
    num = (num * 10 + 7) % k;
    index++;
  }
  if (!flag) {
    cout << -1 << endl;
  } else {
    cout << index << 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 REPR(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

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

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

  int index = 1;
  ll base = 7;
  while (true) {
    if (base % k == 0)
      break;
    base %= k;
    index++;
    base = base * 10 + 7;
    if (index > 10000000) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << index << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

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

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

  int index = 1;
  ll base = 7;
  while (true) {
    if (base % k == 0)
      break;
    base %= k;
    index++;
    base = base * 10 + 7;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n, d, dem = 1;
  cin >> n;
  d = 7;
  if (n % 2 == 0 || n % 5 == 0)
    cout << -1;
  else {
    while (d % n) {
      d = 10 * d + 7;
      d = d % n;
      dem++;
    }
    cout << dem;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n, d, dem = 1;
  cin >> n;
  d = 7;
  while (d % n) {
    d = 10 * d + 7;
    d = d % n;
    dem++;
  }
  cout << dem;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll c = 0;
  ll n;
  cin >> n;

  ll x = 7;
  c = 1;
  for (ll i = 0; i < 1e7; i++) {

    x = x % n;
    if (x == 0) {
      cout << c;
      return 0;
    }
    c++;
    x = x * 10 + 7;
  }
  cout << -1;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll c = 0;
  ll n;
  cin >> n;
  if (n % 2 == 0)
    cout << -1;

  else {
    ll x = 7;
    c = 1;
    while (1) {

      x = x % n;
      if (x == 0) {
        cout << c;
        return 0;
      }
      c++;
      x = x * 10 + 7;
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

int main() {
  long long ch, i = 1, n, q, k, l, r;
  long long j;
  cin >> n;
  ch = 7;
  if (n % 2 != 0) {
    while (ch % n != 0) {
      i++;
      ch = (ch * 10 + 7) % n;
      if (i > n) {
        cout << -1;
        return 0;
      }
    }
    cout << i;
  } else
    cout << -1;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

int main() {
  long long ch, i = 1, n, q, k, l, r;
  long long j;
  cin >> n;
  ch = 7;
  if (n % 2 != 0) {
    while (ch % n != 0) {
      i++;
      ch = (ch * 10 + 7) % n;
    }
    cout << i;
  } else
    cout << -1;

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long int ll;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
//*s.find_by_order(p)   returns the value of pth largest starting from 0
// s.order_of_key(p)   returns no. of items that are strictly < p
// string bin = bitset<64>(m).to_string();     convert decimal m to binary
int main() {
  fast;
  ll t;
  t = 1;
  while (t--) {
    ll k, a, p;
    cin >> k;
    if (k == 1) {
      cout << "1\\n";
      continue;
    }
    if (k % 2 == 0 || k % 5 == 0) {
      cout << "-1\\n";
      continue;
    }
    a = 7;
    p = 1;
    while (1) {
      a = a % k;
      if (a == 0) {
        cout << p << "\\n";
        break;
      }
      p++;
      a = 10 * a + 7;
      // if(p>100000){break;}
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long int ll;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
//*s.find_by_order(p)   returns the value of pth largest starting from 0
// s.order_of_key(p)   returns no. of items that are strictly < p
// string bin = bitset<64>(m).to_string();     convert decimal m to binary
int main() {
  fast;
  ll t;
  t = 1;
  while (t--) {
    ll k, a, p;
    cin >> k;
    if (k == 1) {
      cout << "1\\n";
      continue;
    }
    if (k % 2 == 0) {
      cout << "-1\\n";
      continue;
    }
    a = 7;
    p = 1;
    while (1) {
      a = a % k;
      if (a == 0) {
        cout << p << "\\n";
        break;
      }
      p++;
      a = 10 * a + 7;
      // if(p>100000){break;}
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;
const double eps = 1e-6;
int main() {
  int k;
  scanf("%d", &k);
  if (k % 2 == 0 || k % 10 == 5) {
    puts("-1");
    return 0;
  }
  int cnt = 7;
  int val = 7;
  int ans = 1;
  while (val < k) {
    cnt *= 10;
    val += cnt;
    ++ans;
  }
  val %= k;
  while (val % k) {
    cnt = cnt * 10 % k;
    val = (val + cnt) % k;
    ++ans;
  }
  printf("%d\\n", ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>

#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;
const double eps = 1e-6;
int main() {
  int k;
  scanf("%d", &k);
  if (k % 2 == 0 || k % 10 == 5)
    puts("-1");
  int cnt = 7;
  int val = 7;
  int ans = 1;
  while (val < k) {
    cnt *= 10;
    val += cnt;
    ++ans;
  }
  val %= k;
  while (val % k) {
    cnt = cnt * 10 % k;
    val = (val + cnt) % k;
    ++ans;
  }
  printf("%d\\n", ans);
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  // sengen
  LL k, count, num;
  // nyuryoku
  cin >> k;
  // keisan
  count = 1;
  num = 1;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  k *= 9;
  while (1) {
    num = num * 10 % k;
    if (7 * (num - 1) % k == 0) {
      cout << count << endl;
      return 0;
    }
    count++;
  }
  // syutsuryoku
}

Error: TLE

Fixed submission:

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

int main() {
  // sengen
  LL k, num, add;
  map<LL, LL> mp;
  // nyuryoku
  cin >> k;
  // keisan
  num = 0;
  add = 7;
  LL count = 1;
  int flag = 1;
  while (flag) {
    num = (num + add) % k;
    if (num == 0) {
      cout << count << endl;
      return 0;
    }
    add = add * 10 % k;
    count++;
    if (add == 0) {
      cout << "-1" << endl;
      return 0;
    }
  }
  // syutsuryoku
}