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

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

  int k;
  cin >> k;
  if (~k & 1) {
    cout << -1 << endl;
    return 0;
  }
  int c = 0;
  int cur = 0;
  while (c < 10000000) {
    ++c;
    cur = (cur * 10 + 7) % k;
    if (cur == 0) {
      cout << c << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

  int k;
  cin >> k;
  if (~k & 1) {
    cout << -1 << endl;
    return 0;
  }
  int c = 0;
  int cur = 0;
  for (;;) {
    ++c;
    cur = (cur * 10 + 7) % k;
    if (cur == 0) {
      cout << c << endl;
      return 0;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
// cout << setprecision(20) <<

int main() {
  ll k;
  cin >> k;
  vector<ll> v(k, 0);
  if (k % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  ll i = 0;
  ll rem = 0;
  ll prev_mod;
  ll prev_rem;
  while (true) {
    i++;
    ll cur_rem;
    if (i != 1) {
      cur_rem = prev_mod * 10;
      cur_rem %= k;
      if (cur_rem == 0 && rem != 0) {
        cout << "-1" << endl;
        return 0;
      }
    } else {
      cur_rem = 7 % k;
    }
    rem += cur_rem;
    rem %= k;
    if (rem == 0)
      break;
    prev_mod = cur_rem;
    prev_rem = cur_rem;
    if (v[rem] != 0) {
      cout << "-1" << endl;
      return 0;
    }
    v[rem]++;
  }
  cout << i << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
// cout << setprecision(20) <<

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

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

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


Error: TLE

Fixed submission:

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

int main() {
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = 0;
  ll now = 7;
  while (now % k != 0) {
    now *= 10;
    now += 7;
    now %= k;
    ans++;
  }
  cout << ans + 1 << endl;
}
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;
const double PI = 3.14159265358979323846;

int main() {
  int k;
  cin >> k;
  int a = 0;
  for (int i = 0; i < 2000000; i++) {
    a = (a * 10 + 7) % k;
    if (a == 0) {
      cout << i + 1 << 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 < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int expa(int a, int n) {
  if (n == 0) {
    return 1;
  } else {
    int ans = a * expa(a, n - 1);
    return ans;
  }
}

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

  else {
    int i = 0;
    int ans = 7 * expa(10, i);
    while (ans % k != 0) {
      i++;
      ans += 7 * expa(10, i);
    }

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

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second

using namespace std;

long long power(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p; // Update x if it is more than or
             // equal to p

  if (x == 0)
    return 0; // In case x is divisible by p;

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % p;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}

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

  long long remain = 7 % k;

  long long counter = 1;

  while (remain) {
    remain = remain + 7 * power(10, counter, k);
    remain = remain % k;

    counter++;

    if (counter > 1000000) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << counter << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second

using namespace std;

long long power(long long x, unsigned long long y, long long p) {
  long long res = 1;
  x = x % p; // Update x if it is more than or
             // equal to p

  if (x == 0)
    return 0; // In case x is divisible by p;

  while (y > 0) {
    // If y is odd, multiply x with result
    if (y & 1)
      res = (res * x) % p;

    // y must be even now
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}

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

  long long remain = 7 % k;

  long long counter = 1;

  while (remain) {
    remain = remain + 7 * power(10, counter, k);
    remain = remain % k;

    counter++;

    if (counter > 10000000) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << counter << endl;

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

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

#define sws                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define fo(i, n) for (int i = 0; i < n; i++)

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;

ll eleva(ll x, int y, int mod) {
  ll res = 1;

  while (y) {
    if (y & 1) {
      res = (res * x) % mod;
    }

    y >>= 1;
    x = (x * x) % mod;
  }

  return res;
}

int main() {
  sws;

  ll k;
  cin >> k;

  if (!(k & 1) or (k % 5 == 0)) {
    cout << "-1\\n";
    return 0;
  }

  int resto = 7 % k;
  int cont = 1;
  while (resto != 0) {
    resto = (resto + ((7 * eleva(10, cont, k)) % k)) % k;
    // cout << resto << endl;
    cont++;
  }

  cout << cont << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

#define sws                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define fo(i, n) for (int i = 0; i < n; i++)

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;

ll eleva(ll x, int y, int mod) {
  ll res = 1;

  while (y) {
    if (y & 1) {
      res = (res * x) % mod;
    }

    y >>= 1;
    x = (x * x) % mod;
  }

  return res;
}

int main() {
  sws;

  ll k;
  cin >> k;

  if (!(k & 1)) {
    cout << "-1\\n";
    return 0;
  }

  int resto = 7 % k;
  int cont = 1;
  while (resto != 0) {
    resto = (resto + ((7 * eleva(10, cont, k)) % k)) % k;
    // cout << resto << endl;
    cont++;
  }

  cout << cont << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  if (n % 2 == 0 || n % 5 == 0) {
    cout << -1 << endl;
  } else {
    ll m = 7 % n;
    ll ten = 10;
    ll cnt = 1;
    while (m != 0) {
      cnt++;
      m += ten * 7 % n;
      m %= n;
      ten *= 10;
      ten %= n;
    }
    cout << cnt << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1 << endl;
  } else {
    ll m = 7 % n;
    ll ten = 10;
    ll cnt = 1;
    while (m != 0) {
      cnt++;
      m += ten * 7 % n;
      m %= n;
      ten *= 10;
      ten %= n;
    }
    cout << cnt << 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)
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  int k;
  cin >> k;
  int n = 7;
  int ans = 1;
  while (true) {
    if (n % k == 0) {
      cout << ans << endl;
      return 0;
    }
    n *= 10;
    n += 7;
    n %= k;
    ans++;
    if (ans >= k * 2)
      break;
  }
  cout << -1 << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
  ios::sync_with_stdio(false);
  int k;
  cin >> k;
  int n = 7;
  int ans = 1;
  while (true) {
    if (n % k == 0) {
      cout << ans << endl;
      return 0;
    }
    n *= 10;
    n += 7;
    n %= k;
    ans++;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

Error: TLE

Fixed submission:

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

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

ll k;

int main() {
  cin >> k;
  ll count = 1;
  int seven = 7;
  while (seven % k != 0 && k % 2 != 0 && count <= 1000001) {
    if (seven / k == 0) {
      seven = seven * 10 + 7;
      count = count + 1;
    } else {
      seven = (seven % k) * 10 + 7;
      count = count + 1;
    }
  }
  if (k % 2 == 0 || count >= 1000000)
    cout << -1 << endl;
  else
    cout << count << endl;
}

Error: TLE

Fixed submission:

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

ll k;

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

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int, int>
#define PI 3.1415926535897932384626
#define mod 1000000007
#define fo(i, n) for (i = 0; i < n; i++)
#define endl "\\n"
#define mset(m, v) memset(m, v, sizeof(m))
typedef vector<int> vi;

void solve() {
  int n, i = 1, x = 0;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1;
    return;
  }
  while (i < 100000000) {
    x += 7;
    x %= n;
    if (x == 0) {
      cout << i;
      return;
    }
    x *= 10;
    i++;
  }
  cout << -1 << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int, int>
#define PI 3.1415926535897932384626
#define mod 1000000007
#define fo(i, n) for (i = 0; i < n; i++)
#define endl "\\n"
#define mset(m, v) memset(m, v, sizeof(m))
typedef vector<int> vi;

void solve() {
  int n, i = 1, x = 0;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1;
    return;
  }
  while (i++) {
    x += 7;
    x %= n;
    if (x == 0) {
      cout << i - 1;
      return;
    }
    x *= 10;
  }
  cout << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1; // cin>>t;
  for (int i = 1; i <= t; i++) {
    solve();
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e12
#define pii pair<ll, ll>

#define f(i, a, b) for (ll i = a; i < b; i++)
#define fb(i, a, b) for (ll i = a; i > b; i--)
#define ff first
#define ss second
#define PI 3.141592653589793238
#define pq priority_queue<ll>
#define pqr priority_queue<ll, vector<ll>, greater<ll>()>
using namespace std;
ll pow_mod(ll a, ll b, ll mod) {
  ll res = 1;
  while (b != 0) {
    if (b & 1) {
      res = (res * a) % mod;
    }
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}
void solve() {
  ll k;
  cin >> k;

  ll ans = -1;

  if (k % 7 == 0)
    k /= 7;

  k *= 9;

  ans = -1;
  ll res = 10;

  for (ll i = 1; i <= k; i++) {
    res %= k;

    if (res == 1) {
      ans = i;
      break;
    }

    res = (res * 10) % k;
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  // Start from Here.

  ll t;
  t = 1;
  // cin>>t;
  while (t--)
    solve();

  // Good Bye!
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e12
#define pii pair<ll, ll>

#define f(i, a, b) for (ll i = a; i < b; i++)
#define fb(i, a, b) for (ll i = a; i > b; i--)
#define ff first
#define ss second
#define PI 3.141592653589793238
#define pq priority_queue<ll>
#define pqr priority_queue<ll, vector<ll>, greater<ll>()>
using namespace std;
ll pow_mod(ll a, ll b, ll mod) {
  ll res = 1;
  while (b != 0) {
    if (b & 1) {
      res = (res * a) % mod;
    }
    a = (a * a) % mod;
    b /= 2;
  }
  return res;
}
void solve() {
  ll k;
  cin >> k;
  k *= 9;

  ll cnt = 0;
  for (ll i = 1; i <= k; i++) {
    ll x = pow_mod(10, i, k);
    x -= 1;
    x += k;
    x %= k;
    ll y = 7 % k;

    ll z = (x * y) % k;

    if (z == 0) {
      cout << i << endl;
      return;
    }
  }

  cout << "-1\\n";
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  // Start from Here.

  ll t;
  t = 1;
  // cin>>t;
  while (t--)
    solve();

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

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

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

  lint cur = 7 % k;
  lint mul = 70;
  int res = 1;

  while (cur != 0) {
    cur += mul;
    cur %= k;
    mul *= 10;
    mul %= k;
    res++;
    if (res >= k + 2) {
      cout << "-1" << endl;
      exit(0);
    }
  }

  cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

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

  lint cur = 7 % k;
  lint mul = 70;
  int res = 1;

  while (cur != 0) {
    cur += mul;
    cur %= k;
    mul *= 10;
    mul %= k;
    res++;
  }

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

#include <bits/stdc++.h>
using namespace std;
#include <iomanip>
#include <math.h>
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;
}

const int mod = 1000000007;
const int INF = 1001001001;
int main() {
  int K;
  cin >> K;
  int t = 7;
  vector<bool> use(K, false);
  for (int i = 0; i < K; i++) {
    if (use[t % K]) {
      cout << -1 << endl;
      return 0;
    }
    if (t % K == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    use[t % K] = true;
    t %= K;
    t *= 10;
    t += 7;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#include <iomanip>
#include <math.h>
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;
}

const int mod = 1000000007;
const int INF = 1001001001;
int main() {
  int K;
  cin >> K;
  int t = 7;
  vector<bool> use(K - 1, false);
  for (int i = 0; i < K; i++) {
    if (use[t % K]) {
      cout << -1 << endl;
      return 0;
    }
    if (t % K == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    use[t % K] = true;
    t %= K;
    t *= 10;
    t += 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)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << (x) << endl
#define INF (int)1e9
#define EPS (double)1e-9
#define MOD ((int)1e9 + 7)
using namespace std;
typedef long long llong;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
template <class Type> void line(const Type &a) {
  int cnt = 0;
  for (const auto &elem : a) {
    if (cnt++)
      cerr << ' ';
    cerr << elem;
  }
  cerr << endl;
}

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

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

  int ans = 0;
  llong tmp = 0;
  while (1) {
    ans++;
    tmp = 10 * tmp + 7;
    tmp %= k;
    if (tmp == 0)
      break;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << (x) << endl
#define INF (int)1e9
#define EPS (double)1e-9
#define MOD ((int)1e9 + 7)
using namespace std;
typedef long long llong;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
template <class Type> void line(const Type &a) {
  int cnt = 0;
  for (const auto &elem : a) {
    if (cnt++)
      cerr << ' ';
    cerr << elem;
  }
  cerr << endl;
}

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

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

  int ans = 0;
  llong tmp = 0;
  while (1) {
    ans++;
    tmp = 10 * tmp + 7;
    tmp %= k;
    if (tmp == 0)
      break;
  }

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

#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long K;
  vector<bool> memory;
  cin >> K;
  memory.resize(K, false);
  if (K % 2 == 0) {
    cout << -1 << endl;
  } else {

    long long num = 7;
    int count = 1;
    while (true) {
      num = num % K;
      if (num == 0) {
        cout << count << endl;
        break;
      }
      if (memory[num]) {
        cout << -1 << endl;
        break;
      }
      memory[num] = true;
      num = num * 10 + 7;
      count++;
    }
  }
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
  long long K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << endl;
  } else {

    long long num = 7;
    int count = 1;
    while (true) {
      num = num % K;
      if (num == 0) {
        cout << count << endl;
        break;
      }
      num = num * 10 + 7;
      count++;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

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

  if (k % 2 == 0) {
    cout << -1 << "\\n";
    return 0;
  } else {
    int count = 1;
    long long num = 7;
    while (count <= 1000000) {
      if (num % k == 0) {
        cout << count << "\\n";
        // break;
        return 0;
      }
      count++;
      num = (num * 10 + 7) % k;
    }
  }
  cout << -1 << "\\n";

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

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

  if (k % 2 == 0) {
    cout << -1 << "\\n";
  } else {
    int count = 1;
    long long num = 7;
    while (true) {
      if (num % k == 0) {
        cout << count << "\\n";
        break;
      }
      count++;
      num = (num * 10 + 7) % k;
    }
  }

  return 0;
}