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

#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 5;
const long long inf = 0x3f3f3f3f;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // freopen(".in","r",stdin);
  // freopen(".out","w",stdout);
  long long n;
  cin >> n;
  if (n % 2 == 0 || n % 5 == 0) {
    cout << "-1\\n";
    return 0;
  }
  long long x = 7, ans = 1;
  while (1) {
    if (x % n == 0) {
      cout << ans << endl;
      return 0;
    }
    x = x % n;
    x = x * 10 + 7;
    ans++;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int mod(string a, int b) {
  int d = 0;
  for (int i = 0; i < a.size(); i++)
    d = (d * 10 + (a[i] - '0')) % b; // 求出余数
  return d;
}
int main() {
  int k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << "-1\\n";
    return 0;
  }
  string a = "7";
  while (1) {
    if (mod(a, k) == 0)
      break;
    a += "7";
  }
  cout << a.size();
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

int main() {
  int k{};
  std::cin >> k;
  if (k % 2 == 0) {
    std::cout << -1 << std::endl;
  } else {
    int v{};
    for (int i = 1; i <= k; i++) {
      v = (10 * v + 7) % k;
      if (v == 0) {
        std::cout << i << std::endl;
        return 0;
      }
    }
    std::cout << -1 << std::endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007ll
#define pb push_back
#define vl vector<ll>
#define pll pair<ll, ll>
#define mp make_pair
using namespace std;
#define pi (long double)3.14159265358979323846
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
struct sch {
  ll s, e, t;
};
bool sortinrev(const struct sch &a, const struct sch &b) { return (a.s < b.s); }
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ll x;
  cin >> x;
  if (x % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = 0;
  ll rem = 0;
  while (1) {
    rem *= 10;
    rem += 7;
    ans++;
    if (rem % x == 0)
      break;
    rem = rem % x;
    if (ans > 1000000) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007ll
#define pb push_back
#define vl vector<ll>
#define pll pair<ll, ll>
#define mp make_pair
using namespace std;
#define pi (long double)3.14159265358979323846
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
struct sch {
  ll s, e, t;
};
bool sortinrev(const struct sch &a, const struct sch &b) { return (a.s < b.s); }
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll power(ll x, ll y, ll p) {
  ll res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1; // y = y/2
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ll x;
  cin >> x;
  if (x % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = 0;
  ll rem = 0;
  while (1) {
    rem *= 10;
    rem += 7;
    ans++;
    if (rem % x == 0)
      break;
    rem = rem % x;
  }
  cout << ans << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int main(void) {
  int K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (K % 7 == 0) {
    K /= 7;
  }
  if (K == 1) {
    cout << 1 << endl;
    return 0;
  }
  int mod_all = 1;
  int past_mod = 1;
  for (int i = 2; i <= K; i++) {
    int mod = past_mod * 10 % K;
    if ((mod_all + mod) % K == 0) {
      cout << i << endl;
      return 0;
    }
    past_mod = mod;
    mod_all = (mod_all + mod) % K;
  }
  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main(void) {
  int K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (K % 7 == 0) {
    K /= 7;
  }
  if (K == 1) {
    cout << 1 << endl;
    return 0;
  }
  int mod_all = 1;
  int past_mod = 1;
  for (int i = 2; 1; i++) {
    int mod = past_mod * 10 % K;
    if ((mod_all + mod) % K == 0) {
      cout << i << endl;
      return 0;
    }
    past_mod = mod;
    mod_all = (mod_all + mod) % K;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

  ll ans = 1, num = 7;
  while (num % k != 0) {
    num = (10 * num + 7) % k;
    ans++;
    if (ans > 2 * 1e6) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

  ll ans = 1, num = 7;
  while (num % k != 0) {
    num = (10 * num + 7) % k;
    ans++;
  }

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

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <vector>
#define rip(i, n) for (int i = 0; i < n; i++)
#define Rip(i, n) for (int i = 1; i <= n; i++)
#define RIP(i, a, b) for (int i = a; i < b; i++)
#define all(V) V.begin(), V.end()
#define sec setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<ll, ll>;
ll MOD = 998244353;
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll pow(ll x, ll n, ll mod) {
  x %= mod;
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return (pow((x * x) % mod, n / 2, mod) % mod);
  else
    return (x * pow(x, n - 1, mod) % mod);
}
signed main() {
  long long k;
  cin >> k;
  if (k == 1)
    cout << 1 << endl;
  else if (k % 2 == 0 || k % 5 == 0)
    cout << -1 << endl;
  else {
    ll ans = 1;
    ll nam = 7;
    while (nam % k != 0) {
      nam %= k;
      nam += pow(10, ans, k) * 7;
      nam %= k;
      ans++;
    }
    cout << ans << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <tuple>
#include <vector>
#define rip(i, n) for (int i = 0; i < n; i++)
#define Rip(i, n) for (int i = 1; i <= n; i++)
#define RIP(i, a, b) for (int i = a; i < b; i++)
#define all(V) V.begin(), V.end()
#define sec setprecision;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops");
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
using namespace std;
using ll = long long;
using ld = long double;
using Pa = pair<ll, ll>;
ll MOD = 998244353;
int k;
ll pow(ll x, ll n) {
  x %= k;
  if (n == 0)
    return 1;
  if (n % 2 == 0)
    return (pow((x * x) % k, n / 2));
  else
    return (x * pow(x, n - 1) % k);
}
signed main() {
  cin >> k;
  if (k == 1)
    cout << 1 << endl;
  else if (k % 2 == 0 || k % 5 == 0)
    cout << -1 << endl;
  else {
    ll ans = 1;
    while (true) {
      ll r = (7 * pow(10, ans) - 7) / 9;
      if (r % k == 0)
        break;
      ans++;
    }
    cout << ans << endl;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded


#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

template <class T> using vec = vector<T>;
template <class T> using vec2 = vector<vec<T>>;
template <class T> using vec3 = vector<vec2<T>>;

constexpr int INF = numeric_limits<int>::max();
constexpr ll INFL = numeric_limits<ll>::max();
constexpr ll MOD = 1000000007; // 10^9+7

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

constexpr ll solve(ll k) {
  if (k % 2 == 0 || k % 5 == 0) {
    return -1;
  }

  ll n = 0;
  ll ret = 0;
  while (ret == 0 || n != 0) {
    n = n * 10 + 7;
    n %= k;
    ret++;
  }
  return ret;
}

int main() {
  ll k = 0;
  cin >> k;
  cout << solve(k) << endl;
  return 0;
}


Error: TLE

Fixed submission:


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

template <class T> using vec = vector<T>;
template <class T> using vec2 = vector<vec<T>>;
template <class T> using vec3 = vector<vec2<T>>;

constexpr int INF = numeric_limits<int>::max();
constexpr ll INFL = numeric_limits<ll>::max();
constexpr ll MOD = 1000000007; // 10^9+7

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

// 素因数分解する O(sprt(n))
vector<pair<long long, long long>> prime_factorize(long long n) {
  vector<pair<long long, long long>> res;
  for (long long i = 2; i * i <= n; ++i) {
    if (n % i != 0)
      continue;
    long long ex = 0; // 指数
    while (n % i == 0) {
      ++ex;
      n /= i;
    }
    res.push_back({i, ex});
  }
  if (n != 1)
    res.push_back({n, 1});
  return res;
}

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

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

  ll n = 0;
  ll ret = 0;
  while (ret == 0 || n != 0) {
    n = n * 10 + 7;
    n %= k;
    ret++;
  }

  cout << ret << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for (ll i = 0; i < (n); i++)
#define rep2(i, n) for (ll i = 0; i < (n); i++)
#define rep3(i, a, b) for (ll i = (a); i < (b); i++)
#define rep4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for (ll i = (n)-1; i >= 0; i--)
#define rrep2(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rrep3(i, a, b) for (ll i = (a)-1; i >= (b); i--)
#define rrep4(i, a, b, c) for (ll i = (a)-1; i >= (b); i -= (c))
#define rrep(...)                                                              \\
  overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
const ll INF = 1e18, MOD = 1e9 + 7;
const int iINF = 1e9;

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

  int seven = 7, k, ans = 1;
  cin >> k;
  if (k % 2 == 0) {
    ans = -1;
  } else {
    while (true) {
      if (seven % k == 0)
        break;
      if (ans > 1e7) {
        ans = -1;
        break;
      }
      seven = seven % k;
      seven = seven * 10 + 7;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for (ll i = 0; i < (n); i++)
#define rep2(i, n) for (ll i = 0; i < (n); i++)
#define rep3(i, a, b) for (ll i = (a); i < (b); i++)
#define rep4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for (ll i = (n)-1; i >= 0; i--)
#define rrep2(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rrep3(i, a, b) for (ll i = (a)-1; i >= (b); i--)
#define rrep4(i, a, b, c) for (ll i = (a)-1; i >= (b); i -= (c))
#define rrep(...)                                                              \\
  overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
const ll INF = 1e18, MOD = 1e9 + 7;
const int iINF = 1e9;

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

  int seven = 7, k, ans = 1;
  cin >> k;
  if (k % 2 == 0) {
    ans = -1;
  } else {
    while (true) {
      if (seven % k == 0)
        break;
      seven = seven % k;
      seven = seven * 10 + 7;
      ans++;
    }
  }
  cout << ans << endl;

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

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

int main() {
  long long K = 3, N, x, len = 1, num = 7;
  cin >> K;
  if (K % 2 == 0 || K % 5 == 0) {
    len = -1;
  } else {
    while (true) {
      x = num % K;
      if (x == 0) {
        break;
      } else {
        num = x * 10 + 7;
        len++;
      }
    }
  }
  cout << len;
}

Error: TLE

Fixed submission:

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

int main() {
  long long K, N, D, len = 1, num = 7;
  cin >> K;
  if (K % 2 == 0 || K % 5 == 0) {
    len = -1;
  } else {
    while (true) {
      if (num % K == 0) {
        break;
      }
      len++;
      num = num * 10 + 7;
      if (len >= 1500000) {
        len = -1;
      }
    }
  }
  cout << len;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// for loop
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repe(i, a, n) for (int i = (a); i <= (n); ++i)
#define rrep(i, n, a) for (int i = (n); n > (a); --i)
#define rrepe(i, n, a) for (int i = (n); n >= (a); --i)

// abbreviati
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define ENDL << "\\n"

using ll = long long;
using P = pair<int, int>;
using itn = int;

// constant
const int INF = 1 << 30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI = (acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int k;
  cin >> k;
  int x = 7 % k;
  int cnt = 1;
  set<int> s;
  while (s.count(x) == 0) {
    if (x == 0) {
      cout << cnt ENDL;
      return 0;
    }
    s.insert(x);
    x = (x * 10 + 7) % k;
    cnt++;
  }

  cout << -1 ENDL;
  return 0;
}

Error: TLE

Fixed submission:

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

// for loop
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repe(i, a, n) for (int i = (a); i <= (n); ++i)
#define rrep(i, n, a) for (int i = (n); n > (a); --i)
#define rrepe(i, n, a) for (int i = (n); n >= (a); --i)

// abbreviati
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define ENDL << "\\n"

using ll = long long;
using P = pair<int, int>;
using itn = int;

// constant
const int INF = 1 << 30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI = (acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

bool isPrime(int n) {
  int i;
  if (n < 2)
    return 0;
  else if (n == 2)
    return 1;
  if (n % 2 == 0)
    return 0;
  for (i = 3; i * i <= n; i += 2)
    if (n % i == 0)
      return 0;
  return 1;
}

// adjacency list
vector<int> to[100005];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll k;
  cin >> k;
  int flag = 0;
  ll cnt = 0;
  ll s = 7;
  // rep(i,0,t){
  //     s=s*10+7;
  //     cnt++;
  // }
  if (k % 2 == 0)
    flag = 0;
  else {
    int n = 1;
    while (n) {
      // cout << s ENDL;
      if (s % k == 0) {
        flag = 1;
        n = 0;
        cnt++;
      } else {
        s = s * 10 + 7;
        cnt++;
      }
    }
  }
  // cout << isPrime(11111) ENDL;
  if (flag)
    cout << cnt ENDL;
  else
    cout << -1 ENDL;

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

#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
// #define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; }

std::istream &operator>>(std::istream &in, set<int> &o) {
  int a;
  in >> a;
  o.insert(a);
  return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
  ll a;
  in >> a;
  o.push(a);
  return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
//  std::cout << std::bitset<8>(9);
// const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;

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

  map<int, int> mp;

  {
    int prev = 0;
    while (mp.find(prev) == mp.end()) {
      int next = prev * 10 + 7;
      next %= k;
      mp[prev] = next;
      prev = next;
    }
  }

  bool b = [&] {
    for (auto e : mp) {
      if (e.second == 0)
        return true;
    }
    return false;
  }();
  if (!b) {
    cout << -1 << endl;
    ret();
  }

  int ans = 1;
  for (int prev = 0; mp[prev] != 0; prev = mp[prev]) {
    ans++;
  }

  cout << ans << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
// #define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; }

std::istream &operator>>(std::istream &in, set<int> &o) {
  int a;
  in >> a;
  o.insert(a);
  return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
  ll a;
  in >> a;
  o.push(a);
  return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
//  std::cout << std::bitset<8>(9);
// const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;

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

  map<int, int> mp;

  {
    int prev = 0;
    while (mp.find(prev) == mp.end()) {
      int next = prev * 10 + 7;
      next %= k;
      mp[prev] = next;
      prev = next;
    }
  }

  int ans = 1;
  set<int> use;
  for (int prev = 0; mp[prev] != 0; prev = mp[prev]) {
    ans++;
    if (use.find(prev) != use.end()) {
      cout << -1 << endl;
      ret();
    }
    use.insert(prev);
  }

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

#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define reps(i, s, n) for (int i = s, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void) {
  ll K;
  cin >> K;
  ll d = 7 % K;
  ll ini = d, count = 1;
  while (d != 0) {
    count++;
    d = (d * 10 + 7) % K;
    if (count >= K + 2) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << count << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define reps(i, s, n) for (int i = s, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
typedef long double ld;
const char sp = ' ';

using namespace boost::multiprecision;
using namespace std;

int main(void) {
  ll K;
  cin >> K;
  ll d = 7 % K;
  ll ini = d, count = 1;
  while (d != 0) {
    count++;
    d = (d * 10 + 7) % K;
    if (d == ini) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void solve() {
  int k;
  cin >> k;

  if (k % 7 == 0) {
    k /= 7;
  }
  if (gcd(10, k) != 1) {
    cout << -1;
    return;
  }

  long v = 1 % k;
  int len = 1;
  while (v != 0) {
    v = (10 * v + 1) % k;
    len++;
  }
  cout << len;
}
int main() { solve(); }

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {

  int k;
  cin >> k;

  if (k % 7 == 0) {
    k /= 7;
  }
  if (gcd(10, k) != 1) {
    cout << -1;
  }

  long v = 1 % k;
  int len = 1;
  while (v != 0) {
    v = (10 * v + 1) % k;
    len++;
  }
  cout << len;
}