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

#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1;
    return;
  }
  int curr = 7;
  if (k == 7 || k == 1) {
    cout << 1;
    return;
  }
  for (int i = 2; i <= 1e7; i++) {
    int val = (((curr % k) * (10 % k)) % k + (7 % k)) % k;
    if (val == 0) {
      cout << i;
      return;
    }
    curr = val;
  }
  cout << -1;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1;
    return;
  }
  string s = "7";
  int last = 0;
  bool no = true;
  for (int i = 1; i <= 1e6; i++) {
    int curr = ((last * (10 % k)) % k + (7 % k)) % k;
    if (curr % k == 0) {
      cout << i;
      no = false;
      break;
    }
    last = curr;
    s = s + "7";
  }
  if (no)
    cout << -1;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  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;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

ll x;

bool chk(int x) {
  if (x == 0)
    return 0;
  while (x) {
    if (x % 10 != 1)
      return 0;
    x /= 10;
  }
  return 1;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> x;
  int cnt = 0;
  ll tmp = 0;
  if (x % 7 == 0)
    x /= 7;
  if (x == 1) {
    cout << 1;
    return 0;
  }
  while (1) {
    int y = ((11 - tmp % 10) % 10);

    if (chk(tmp)) {
      while (tmp)
        tmp /= 10, cnt++;
      cout << cnt;
      return 0;
    }

    bool pos = 0;
    for (int i = 0; i < 10; i++)
      if (i * x % 10 == y) {
        tmp += x * i;
        tmp /= 10;
        pos = 1;
        break;
      }
    if (pos)
      cnt++;
    else {
      cout << -1;
      return 0;
    }
  }
}


Error: TLE

Fixed submission:

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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

ll x;

bool chk(int x) {
  if (x == 0)
    return 0;
  while (x) {
    if (x % 10 != 1)
      return 0;
    x /= 10;
  }
  return 1;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> x;
  int cnt = 0;
  ll tmp = 0;
  if (x % 7 == 0)
    x /= 7;
  while (1) {
    int y = ((11 - tmp % 10) % 10);

    if (chk(tmp)) {
      while (tmp)
        tmp /= 10, cnt++;
      cout << cnt;
      return 0;
    }

    bool pos = 0;
    for (int i = 0; i < 10; i++)
      if (i * x % 10 == y) {
        tmp += x * i;
        tmp /= 10;
        pos = 1;
        break;
      }
    if (pos)
      cnt++;
    else {
      cout << -1;
      return 0;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

  unsigned int i = 0;
  unsigned int ai = 0;
  while (true) {
    i++;
    ai = (ai * 10 + 7) % K;
    if (ai == 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

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

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

  unsigned int i = 0;
  unsigned int ai = 0;
  while (true) {
    i++;
    ai = ai * 10 + 7;
    if (ai % K == 0) {
      cout << i << endl;
      return 0;
    }
  }
  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 sz(x) int(x.size())
#define show(x)                                                                \\
  {                                                                            \\
    for (auto i : x) {                                                         \\
      cout << i << " ";                                                        \\
    }                                                                          \\
    cout << endl;                                                              \\
  }
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int K;
  cin >> K;
  int ans = 1;
  ll power = 1;
  ll cur = 0;
  while (1) {
    cur += power * 7 % K;
    cur %= K;
    if (cur % K == 0) {
      cout << ans << '\\n';
      return 0;
    }
    if (ans >= 10000000)
      break;
    power *= 10;
    power %= K;
    ans++;
  }
  cout << -1 << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x)                                                                \\
  {                                                                            \\
    for (auto i : x) {                                                         \\
      cout << i << " ";                                                        \\
    }                                                                          \\
    cout << endl;                                                              \\
  }
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int K;
  cin >> K;
  set<ll> st;
  int ans = 1;
  ll power = 1;
  ll cur = 0;
  while (1) {
    cur += power * 7 % K;
    if (cur % K == 0) {
      cout << ans << '\\n';
      return 0;
    }
    if (st.find(cur) != st.end())
      break;
    st.insert(cur);
    power *= 10;
    power %= K;
    ans++;
  }
  cout << -1 << '\\n';
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

set<int> s;
int n, r, k, len = 1;

int main() {
  ios::sync_with_stdio(false);
  cin >> k;
  n = 7;
  r = n % k;

  while (r != 0) {
    if (s.find(r) != s.end()) {
      cout << -1 << endl;
      return 0;
    }
    s.insert(r);
    n = r * 10 + 7;
    r = n % k;
    len++;
  }

  cout << len << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

set<int> s;
int n, r, k, len = 1;

int main() {
  ios::sync_with_stdio(false);
  cin >> k;
  n = 7;
  r = n % k;

  while (r != 0) {
    if (s.find(r) != s.end()) {
      cout << "-1" << endl;
      return 0;
    }
    n = n * 10 + 7;
    r = n % k;
    len++;
  }

  cout << len << endl;
  return 0;
}
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 tmpk = k, rank = 0;

  while (tmpk) {
    tmpk /= 10;
    rank++;
  }

  ll ans = 1;
  if (k % 2 == 0 && k / 2 > 0) {
    ans = -1;
  } else {
    ll sevens = 7;
    for (int i = 1; i < rank; i++) {
      sevens *= 10;
      sevens += 7;
      ans++;
    }
    ll amari = sevens % k;
    while (amari) {
      amari %= k;
      if (amari == 0)
        break;
      ans++;
      amari *= 10;
      amari += 7;
      if (ans >= 100000000) {
        ans = -1;
        break;
      }
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

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

  ll tmpk = k, rank = 0;

  while (tmpk) {
    tmpk /= 10;
    rank++;
  }

  ll ans = 1;
  if (k % 2 == 0 && k / 2 > 0) {
    ans = -1;
  } else {
    ll sevens = 7;
    for (int i = 1; i < rank; i++) {
      sevens *= 10;
      sevens += 7;
      ans++;
    }
    ll amari = sevens % k;
    while (amari) {
      amari %= k;
      if (amari == 0)
        break;
      ans++;
      amari *= 10;
      amari += 7;
      if (ans >= 1000000000) {
        ans = -1;
        break;
      }
    }
  }

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

#include <bits/stdc++.h>

using namespace std;

// #define int long long
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, n) for (ll i = 0; i <= n; i++)

ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);

const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main() {
  ios_base::sync_with_stdio(false);
  ll k;
  cin >> k;
  vector<ll> a(k, 0);
  a[1] = 7;
  for (int i = 1; i <= k; i++) {
    if (i != 1) {
      a[i] = (10 * a[i - 1] + 7);
      a[i] %= k;
    }
    if (a[i] % k == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

// #define int long long
using ll = long long;
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, n) for (ll i = 0; i <= n; i++)

ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);

const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main() {
  ios_base::sync_with_stdio(false);
  ll k;
  cin >> k;
  vector<ll> a(k, 7);
  for (int i = 1; i < 1000000; i++) {
    if (i != 1) {
      a[i] = 10 * a[i - 1] + 7;
    }
    if (a[i] % k == 0) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>

using namespace std;

int main(void) {
  unsigned int k;

  cin >> k;

  int ans = 0;
  int remainder = 0;
  for (int i = 0; i < k; i++) {
    ans++;
    remainder = (remainder * 10 + 7) % k;
    if (remainder == 0)
      break;
    if (i == k - 1)
      ans = -1;
  }

  cout << ans;

  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>

using namespace std;

int main(void) {
  unsigned int k;

  cin >> k;

  int ans = 0;
  int remainder = 0;
  for (int i = 0;; i++) {
    ans++;
    remainder = (remainder * 10 + 7) % k;
    if (remainder == 0)
      break;
    if (i >= k - 1)
      ans = -1;
  }

  cout << ans;

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

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

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

  int k;
  cin >> k;
  ll cs = 0;
  for (i = 1; i <= k + 1; i++) {
    cs = cs * 10 + 7;
    if (cs % k == 0) {
      cout << i << endl;
      return 0;
    }
    cs = cs % k;
  }
  cout << -1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

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

  int k;
  cin >> k;
  if (k % 2 == 0 || k % 4 == 0 || k % 8 == 0 || k % 16 == 0 || k % 32 == 0 ||
      k % 64 == 0 || k % 5 == 0 || k % 25 == 0 || k % 125 == 0 ||
      k % 625 == 0 || k % 3125 == 0 || k % 15625 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll chushu = 0;
  for (i = 1;; i++) {
    chushu = chushu * 10 + 7;
    if (chushu % k == 0)
      break;
  }
  cout << i << 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 repbit(bit, n) for (int bit = 0; bit < (1 << n); bit++)
using namespace std;
typedef long long ll;

const int INF = 1001001001;
// const ll INF = 1000000000000000000;

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

  if (k % 2 == 0 or k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans;
  vector<int> s;
  s.push_back(0);
  int id = 0;
  ll term = 7 % k;
  while (true) {
    int &ref = s.back();
    if (id != 0 and ref == 0) {
      ans = id;
      break;
    }
    s.push_back((ref + term) % k);
    id++;
    term *= 10;
    term %= k;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

const int INF = 1001001001;
// const ll INF = 1000000000000000000;

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

  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans;
  vector<int> s;
  s.push_back(0);
  int id = 0;
  ll term = 7 % k;
  while (true) {
    int &ref = s.back();
    if (id != 0 and ref == 0) {
      ans = id;
      break;
    }
    s.push_back((ref + term) % k);
    id++;
    term *= 10;
    term %= k;
  }
  cout << ans << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;

int main() {
  /*int x;
  cin >> x;
  if (x >= 30)puts("Yes");
  else puts("No");*/

  /*ll n, d;
  cin >> n >> d;
  int ans = 0;
  ll x, y;
  rep(i, n) {
          cin >> x >> y;
          if (sqrt(x * x + y * y) <= d)ans++;
  }
  cout << ans;*/

  int k;
  cin >> k;
  if (k % 2 == 0)
    puts("-1");
  else {
    int a = 7;
    int ans = 1;
    vector<int> p(k);
    while (a % k != 0) {
      if (p[a]) {
        ans = -1;
        break;
      }
      p[a] = 1;
      a = a * 10 + 7;
      a = a % k;
      ans++;
    }
    cout << ans;
  }

  /*int n;
  cin >> n;
  string s;
  cin >> s;
  int wnum = 0;
  rep(i, n) {
          if (s[i] == 'W')wnum++;
  }
  rep(i, n) {
          if (s[i] == 'W' && i > n - 1 - wnum)wnum--;
  }
  cout << wnum;*/
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;

int main() {
  /*int x;
  cin >> x;
  if (x >= 30)puts("Yes");
  else puts("No");*/

  /*ll n, d;
  cin >> n >> d;
  int ans = 0;
  ll x, y;
  rep(i, n) {
          cin >> x >> y;
          if (sqrt(x * x + y * y) <= d)ans++;
  }
  cout << ans;*/

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

#include <bits/stdc++.h>
/*
 *    coder :: ATUL_PANDEY_2608
 *        >>> INDIA <<<
 */
using namespace std;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define maxx 200006
#define ll long long
#define quick ios_base::sync_with_stdio(NULL), cin.tie(0);
#define listll vector<long long>
#define listi vector<int>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define minheap priority_queue<long long, vector<long long>, greater<long long>>
#define rep(i, a, b) for (int i = a; i < b; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// end of #define

// define globals ...

// write function from here ...

int Main() {

  long long num = 7;
  int check = 1;
  long long cnt;
  cin >> cnt;

  set<long long> st;
  st.insert(7);

  bool flag = false;

  if (cnt % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (num % cnt != 0) {
    num = (num % cnt) * 10 + 7;
    if (st.find(num) != st.end()) {
      flag = true;
      break;
    }
    st.insert(num);

    check++;
  }
  if (flag == true) {
    cout << -1 << endl;
    return 0;
  }
  cout << check << endl;

  return 0;
}

int main() {
  quick;
  int t = 1;
  // cin>>t;
  while (t--)
    Main();

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
/*
 *    coder :: ATUL_PANDEY_2608
 *        >>> INDIA <<<
 */
using namespace std;

// #define  part ..
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define maxx 200006
#define ll long long
#define quick ios_base::sync_with_stdio(NULL), cin.tie(0);
#define listll vector<long long>
#define listi vector<int>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define minheap priority_queue<long long, vector<long long>, greater<long long>>
#define rep(i, a, b) for (int i = a; i < b; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// end of #define

// define globals ...

// write function from here ...

int Main() {

  long long num = 7;
  int check = 1;
  long long cnt;
  cin >> cnt;

  while (num % cnt != 0) {
    num = (num % cnt) * 10 + 7;
    check++;
  }
  cout << check << endl;

  return 0;
}

int main() {
  quick;
  int t = 1;
  // cin>>t;
  while (t--)
    Main();

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

#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++)
#define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init()                                                                 \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0);                                                             \\
  std::cout << fixed << setprecision(15);
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

int main() {
  Init();
  ll k;
  cin >> k;
  ll ans = 1;
  ll num = 7;
  vi chk(1000001, 0);

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

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for (ll i = 0, i##_len = (ll)(n); i < i##_len; i++)
#define repf(i, n) for (ll i = 1, i##_len = (ll)(n + 1); i < i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init()                                                                 \\
  std::ios::sync_with_stdio(false);                                            \\
  std::cin.tie(0);                                                             \\
  std::cout << fixed << setprecision(15);
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

int main() {
  Init();
  ll k;
  cin >> k;
  ll ans = 1;
  ll num = 7;

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

  while (num % k != 0) {
    num %= k;
    num = num * 10 + 7;
    ans++;
  }
  cout << ans << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

//
#include <bits/stdc++.h>
#define endl "\\n"
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) // vectorの中身を見る
{
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
void map_p(map<int, int> &d) {
  cout << "map: ";
  for (auto a : d) {
    cout << "{" << a.first << ":" << a.second << "}";
  }
  cout << endl;
} // mapの中身を見る
void set_p(set<int> &d) {
  cout << "set: ";
  for (int a : d) {
    cout << a << " ";
  }
  cout << endl;
} // setの中身を見る

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  ll k, L, num = 1, ans = -1;
  cin >> k;
  if (9 * k % 7 == 0)
    L = 9 * k / 7;
  else
    L = 9 * k;
  if (L % 2 == 0 || L % 5 == 0)
    ans = -1;
  else {
    for (int i = 1; i <= L; i++) {
      num *= 10;
      num %= L;
      if (num == 1) {
        ans = i;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

//
#include <bits/stdc++.h>
#define endl "\\n"
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ipair;
typedef pair<ll, ll> lpair;
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) // vectorの中身を見る
{
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
void map_p(map<int, int> &d) {
  cout << "map: ";
  for (auto a : d) {
    cout << "{" << a.first << ":" << a.second << "}";
  }
  cout << endl;
} // mapの中身を見る
void set_p(set<int> &d) {
  cout << "set: ";
  for (int a : d) {
    cout << a << " ";
  }
  cout << endl;
} // setの中身を見る

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  ll k;
  cin >> k;
  if (k % 2 == 0)
    cout << -1 << endl;
  else {
    ll n = 1, ten_ = 10;
    while (true) {
      if (7 * (ten_ - 1) % (9 * k) == 0)
        break;
      ten_ *= 10, n++;
    }
    cout << n << endl;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int K, n = 1; // n = n項目
  int sept = 7;
  int found = 0;
  map<int, int> hist;
  std::cin >> K;

  if (K % 2 == 0) {
    n = -1;
  } else {
    while (found == 0) {
      if (sept % K == 0) {
        found = 1;
      } else {
        // 次のseptを作りに行く
        sept = sept % K;
        if (hist.count(sept)) {
          n = -1;
          break;
        } else {
          hist[sept] = 1;
        }
        sept = 10 * sept + 7;
        //                std::cout << sept << "\\n";
        n++;
      }
    }
  }
  std::cout << n;
}


Error: TLE

Fixed submission:

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

int main() {
  int K, n = 1; // n = n項目
  int sept = 7;
  int found = 0;
  std::cin >> K;

  if (K % 2 == 0) {
    n = -1;
  } else {
    while (found == 0) {
      if (sept % K == 0) {
        found = 1;
      } else {
        // 次のseptを作りに行く
        sept = sept % K;
        sept = 10 * sept + 7;
        //                std::cout << sept << "\\n";
        n++;
      }
    }
  }
  std::cout << n;
}