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

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

signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, i, ans;
  cin >> n;

  ans = 0;
  int val = 0;
  i = 0;
  while (i < 10000000) {
    if (val < n) {
      val *= 10;
      val += 7;
      ans++;
    } else {
      val %= n;
      if (val == 0) {
        cout << ans << endl;
        return 0;
      }
    }
    i++;
  }

  cout << -1 << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

signed main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, i, ans;
  cin >> n;

  ans = 0;
  int val = 0;
  while (ans < 2000000000) {
    if (val < n) {
      val *= 10;
      val += 7;
      ans++;
    } else {
      val %= n;
      if (val == 0) {
        cout << ans << endl;
        return 0;
      }
    }
    // cout<<val<<endl;
    if (ans == 999983)
      cout << "raj " << val << endl;
  }

  cout << -1 << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define ft                                                                     \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
#define pi pair<int, int>
#define pb push_back
#define F first
#define S second
#define B begin()
#define E end()
const int N = 5e7 + 3;
// string s,p;
// vector<int>v;
// map<int,int>mp;

int main() {
  ft ll t, i, j, n, m, l, r;
  string s;
  cin >> n;
  s += "7";
  r = 0;
  for (i = 1; i < N; i++) {
    r = (r * 10 + (s[i - 1] - 48)) % n;
    if (r == 0) {
      cout << i << "\\n";
      return 0;
    }
    s += "7";
  }
  cout << "-1\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ft                                                                     \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
#define pi pair<int, int>
#define pb push_back
#define F first
#define S second
#define B begin()
#define E end()
const int N = 2e5 + 3;
// string s,p;
// vector<int>v;
// map<int,int>mp;

int main() {
  ft ll t, i, j, n, m, l, r;
  string s;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1\\n";
    return 0;
  }
  s += "7";
  r = 0;
  for (i = 1;; i++) {
    r = (r * 10 + (s[i - 1] - 48)) % n;
    if (r == 0) {
      cout << i << "\\n";
      break;
    }
    s += "7";
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll K;
  cin >> K;
  ll ai = 7;
  for (int i = 1; i <= K; i++) {
    if (ai % K == 0) {
      cout << i << endl;
      return 0;
    }
    ai = (ai * 10 + 7) % K;
    // cout<<ai<<endl;
  }

  cout << "-1" << endl;
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  ll K;
  string str;
  cin >> K;
  string stK = to_string(K);
  ll keta = stK.length();
  rep(i, keta) { str += "7"; }
  string fstr = str;
  ll amari;
  amari = stoi(str) % K;
  if (amari == 0) {
    cout << keta << endl;
    return 0;
  }
  while (1) {
    str += "7";

    ll num = stoi(str);
    if (num % K == 0) {
      cout << str.length() << endl;
      return 0;
    }
    if (num % K == amari) {
      ll num1 = stoi(str);
      ll num2 = stoi(fstr);
      ll num3 = num1 - num2;
      if ((num3 % K) != 0)
        break;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define PI 3.1415926535897932384626433832795
#define MOD 100000007
#define F first
#define S second
#define aLL(str) (str).begin(), (str).end()
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
#define ld long double
#define lcm(a, b) (a * b) / __gcd(a, b)
#define flu(i, a, b) for (ll i = a; i < b; i++)
#define blu(i, a, b) for (ll i = a; i >= b; i--)
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define Unique(X) (X).erase(unique(all(X)), (X).end())
#define all(v) v.begin(), v.end()
typedef vector<ll> vl;
typedef map<ll, ll> ml;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
char e = '\\n';
ll i, j, le;

int main() {
  IOS;
  int t;
  t = 1;
  while (t--) {
    ll ans = -1;
    ll n2;
    cin >> n2;
    if (n2 % 2 == 0 || n2 % 5 == 0) {
      cout << -1 << e;
    } else {
      ans = 1;
      ll num = 7;
      while (num % n2 != 0) {
        num = (num * 10 + 7) % n2;
        ans++;
      }
      cout << ans << e;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define in insert
#define PI 3.1415926535897932384626433832795
#define MOD 100000007
#define F first
#define S second
#define aLL(str) (str).begin(), (str).end()
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
#define ld long double
#define lcm(a, b) (a * b) / __gcd(a, b)
#define flu(i, a, b) for (ll i = a; i < b; i++)
#define blu(i, a, b) for (ll i = a; i >= b; i--)
#define upper(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define Unique(X) (X).erase(unique(all(X)), (X).end())
#define all(v) v.begin(), v.end()
typedef vector<ll> vl;
typedef map<ll, ll> ml;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
char e = '\\n';
ll i, j, le;

int main() {
  IOS;
  int t;
  t = 1;
  while (t--) {
    ll ans = -1;
    string k;
    cin >> k;
    ll n = k.size();
    ll n2 = stoi(k);
    if (n2 % 2 != 0) {
      ans = 1;
      ll num = 7;
      while (num % n2 != 0) {
        num = (num * 10 + 7) % n2;
        ans++;
      }
      cout << ans << e;
    } else if (n2 % 2 == 0 || n2 % 5 == 0) {
      cout << -1 << e;
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef pair<int, int> ii;

#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define each(x, s) for (auto &x : s)
#define loop(x) for (int i = 0; i < x; i++)
#define vloop(v, x) for (int v = 0; v < x; v++)
#define avg(l, r) l + (r - l) / 2
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define endl "\\n"

const ll mod = 1000000007;

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

  ll k;
  cin >> k;
  vi aux(10, INF);
  int r = k % 10;
  for (int i = 1; i < 10; i++) {
    int x = r * i % 10;
    aux[x] = min(aux[x], i);
  }
  ll ans = 0, sum = 0;
  do {
    int x = 7 - sum % 10;
    if (x < 0)
      x += 10;
    if (aux[x] == INF) {
      ans = -1;
      break;
    } else {
      sum += k * aux[x];
    }
    while (sum % 10 == 7)
      sum /= 10, ans++;
  } while (sum);
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef pair<int, int> ii;

#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3f
#define each(x, s) for (auto &x : s)
#define loop(x) for (int i = 0; i < x; i++)
#define vloop(v, x) for (int v = 0; v < x; v++)
#define avg(l, r) l + (r - l) / 2
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define endl "\\n"

const ll mod = 1000000007;

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

  ll k;
  cin >> k;
  ll ans = 0, sum = 0;
  do {
    sum += k;
    while (sum % 10 == 7)
      sum /= 10, ans++;
  } while (sum);
  cout << ans << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define f(i, a, b) for (ll i = a; i < b; i++)
#define af(i, a, b) for (ll i = a; i >= b; i--)
#define rep(i, a, b, k) for (ll i = a; i < b; i += k)
#define arep(i, a, b, k) for (ll i = a; i >= b; i -= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort(a.begin(), a.end())
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define ller                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tsie(nullptr);                                                           \\
  cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
const ll mod = 1e9 + 7;
const ll MAX = 12;
const ll inf = 1e9 + 7;

int main() {
  fastio;
  ll n, ind = 0;
  cin >> n;
  f(i, 1, 2e6) {
    ind = (ind * 10 + 7) % n;
    if (!ind) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define f(i, a, b) for (ll i = a; i < b; i++)
#define af(i, a, b) for (ll i = a; i >= b; i--)
#define rep(i, a, b, k) for (ll i = a; i < b; i += k)
#define arep(i, a, b, k) for (ll i = a; i >= b; i -= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort(a.begin(), a.end())
#define fastio                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define ller                                                                   \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tsie(nullptr);                                                           \\
  cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
const ll mod = 1e9 + 7;
const ll MAX = 1e9;
const ll inf = 1e9 + 7;

int main() {
  fastio;
  ll k, val;
  string s = "";
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  f(i, 1, MAX) {
    s.pb('7');
    val = stoll(s);
    if (val % k == 0) {
      break;
    }
  }
  cout << sz(s) << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

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

unsigned long long int m = 10;

int seven(unsigned long long int n) {

  for (int i = 1;; i++) {
    m = m % n;
    if (m == 1) {
      return i;
    } else {
      m = m * 10;
    }
  }
}

int main() {

  unsigned long long int k = 0;
  cin >> k;

  if (k % 2 == 0 || k % 5 == 0) {

    cout << -1 << endl;

  } else if (k % 7 == 0) {

    k = 9 * k / 7;
    cout << seven(k) << endl;

  } else {

    k = 9 * k;
    cout << seven(k) << endl;
  }
}


Error: 0

Fixed submission:

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

unsigned long long int i = 1;
unsigned long long int m = 10;

int seven(unsigned long long int n) {

  m = m % n;

  if (m == 1)
    return i;
  else {

    i++;
    m = m * 10;
    seven(n);
  }
}

int main() {

  unsigned long long int k = 0;
  cin >> k;

  if (k % 2 == 0 || k % 5 == 0) {

    cout << -1 << endl;

  } else if (k % 7 == 0) {

    k = 9 * k / 7;
    cout << seven(k) << endl;

  } else {

    k = 9 * k;
    cout << seven(k) << endl;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 200005
const ll INF = 1000000000000000001;
const ll MOD = 1000000007;

// vector< vector<ll> > g(N);
// vector< pair<ll, pair< ll, ll > > > g(N);
// ll vis[N] = {0}, par[N] = {0}, child[N] = {0},cnt = 0;

void solve() {
  ll n;
  cin >> n;
  ll i = 7, cnt = 0;
  while (cnt <= 50000000) {
    cnt++;
    if (i % n == 0) {
      cout << cnt << "\\n";
      return;
    }
    i *= 10;
    i += 7;
    i %= n;
  }
  cout << "-1\\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  // ll t;cin >> t;for(ll index=1; index<=t; index++){
  // cout << "Case #" << index << ": " ;
  solve();
  // }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 200005
const ll INF = 1000000000000000001;
const ll MOD = 1000000007;

// vector< vector<ll> > g(N);
// vector< pair<ll, pair< ll, ll > > > g(N);
// ll vis[N] = {0}, par[N] = {0}, child[N] = {0},cnt = 0;

void solve() {
  ll n;
  cin >> n;
  ll i = 7, cnt = 0;
  while (cnt <= 500000000) {
    cnt++;
    if (i % n == 0) {
      cout << cnt << "\\n";
      return;
    }
    i *= 10;
    i += 7;
    i %= n;
  }
  cout << "-1\\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  // ll t;cin >> t;for(ll index=1; index<=t; index++){
  // cout << "Case #" << index << ": " ;
  solve();
  // }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {

  int K;
  cin >> K;

  int i = 1;

  int L;
  if (K % 7 == 0) {
    L = 9 * K / 7;
  } else {
    L = 9 * K;
  }

  int check = 10 % L;

  if (K % 2 == 0 || K % 5 == 0) {
    i = -1;
    cout << i << endl;
  } else {
    while (true) {
      if (check == 1) {
        cout << i << endl;
        break;
      }
      check = (check * 10) % L;
      i++;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {

  int K;
  cin >> K;

  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1 << endl;
  } else {
    int i = 1;
    int ans = 1;
    while (true) {
      int x = 7 * (pow(10, i) - 1) / 9;
      if (x % K == 0) {
        cout << ans << endl;
        break;
      }
      ans++;
      i++;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int K;
  cin >> K;
  int ans = 1;
  int ones[K];
  for (int i = 0; i < K; i++) {
    ones[i] = 0;
  }

  bool exist = true;
  int n = 7 % K;
  while (true) {
    if (n == 0)
      break;
    if (n > 0 && ones[n] > 0) {
      exist = false;
      break;
    }
    ones[n]++;
    n = (n * 10 + 7) % K;
    ans++;
  }
  if (!exist)
    ans = -1;
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

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

int main() {
  int K;
  cin >> K;
  int a = 7;
  int c = 1;
  int q = K % 2;
  int w = K % 5;
  if (q == 0 || w == 0) {
    cout << -1 << endl;
  }

  else {

    while (true) {

      a = a % K;

      if (a == 0) {
        cout << c << endl;
        break;
      } else {
        a = a * 10 + 7;
        c++;
      }
    }
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int K;
  cin >> K;
  int a = 0;
  int c = 1;
  int q = K % 2;
  int w = K % 5;
  if (q == 0) {
    cout << -1 << endl;
  }

  else if (w == 0) {
    cout << -1 << endl;
  }

  else {

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

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define LLU long long unsigned
#define rarr(arr, n)                                                           \\
  for (int aab = 0; aab < n; aab++) {                                          \\
    cin >> arr[aab];                                                           \\
  }
#define parr(arr, n)                                                           \\
  for (int aab = 0; aab < n; aab++) {                                          \\
    cout << arr[aab] << " ";                                                   \\
  }
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\\n";

#define freopen                                                                \\
  freopen("in.txt", "r", stdin);                                               \\
  freopen("out.txt", "w", stdout);                                             \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);

int main() {
  long long int n;
  cin >> n;
  if (n % 2 == 0 || n % 5 == 0) {
    cout << -1;
  } else {
    long long int ans = 1, number = 7;
    while (1) {
      if (number % n == 0) {
        cout << ans;
        return 0;
      }
      ans++;
      number = (number * 10 + 7) % n;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define LLU long long unsigned
#define rarr(arr, n)                                                           \\
  for (int aab = 0; aab < n; aab++) {                                          \\
    cin >> arr[aab];                                                           \\
  }
#define parr(arr, n)                                                           \\
  for (int aab = 0; aab < n; aab++) {                                          \\
    cout << arr[aab] << " ";                                                   \\
  }
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\\n";

#define freopen                                                                \\
  freopen("in.txt", "r", stdin);                                               \\
  freopen("out.txt", "w", stdout);                                             \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);

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

#include <bits/stdc++.h>
#define rep(a, b) for (int i = a; i < b; i++)
using namespace std;

int ja_foi[1123456];

int main() {
  int x, indc = 1;
  long long resto = 7;

  scanf("%d", &x);

  if (x % 2 == 0) {
    puts("-1");
  } else {
    while (1) {
      if (resto % x == 0) {
        break;
      }

      if (ja_foi[resto]) {
        indc = -1;
        break;
      } else {
        ja_foi[resto] = 1;
      }

      resto = ((resto * 10) + 7) % x;
      // printf("%lld\\n", resto);
      indc++;
    }
    printf("%d\\n", indc);
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(a, b) for (int i = a; i < b; i++)
using namespace std;

int ja_foi[1123456];

int main() {
  int x, indc = 1;
  long long resto = 7;

  scanf("%d", &x);

  if (x % 2 == 0 and x % 5 == 0) {
    puts("-1");
  } else {
    while (1) {
      if (resto % x == 0) {
        break;
      }

      if (ja_foi[resto]) {
        indc = -1;
        break;
      } else {
        ja_foi[resto];
      }

      resto = ((resto * 10) + 7) % x;
      indc++;
    }
    printf("%d\\n", indc);
  }

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

#include <bits/stdc++.h>

using namespace std;

void fastio() {
  cin.tie(nullptr);
  cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9 + 7;
const LL INF = LLONG_MAX;
const LL N = 1e6 + 1;

int main() {
  fastio();

  LL k;
  cin >> k;

  LL low = k % 10;

  if (low == 2 || low == 4 || low == 5 || low == 6 || low == 8 || low == 0) {
    cout << -1 << "\\n";
    return 0;
  }

  LL mod = 7 % k, c = 1;
  while (mod != 0) {
    mod = ((mod * 10) + 7) % k;
    c++;
  }
  cout << c << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

void fastio() {
  cin.tie(nullptr);
  cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9 + 7;
const LL INF = LLONG_MAX;
const LL N = 1e6 + 1;

int main() {
  fastio();

  LL k;
  cin >> k;

  LL low = k % 10;

  if (low == 2 || low == 4 || low == 5 || low == 6 || low == 8) {
    cout << -1 << "\\n";
    return 0;
  }

  LL mod = 7 % k, c = 1;
  while (mod != 0) {
    mod = ((mod * 10) + 7) % k;
    c++;
  }
  cout << c << "\\n";
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define rep(a, b, c, i) for (int i = a; i < b; i++)
#define ff first
#define ss second
#define newl "\\n"

using namespace std;

class Repsept {
public:
  ll first7(ll k) {
    ll count = 1;
    ll x = 7;
    if (k == 1 || k == 7)
      return 1;
    if (k % 2 == 0 || k % 5 == 0)
      return -1;
    while (x > 0) {
      x = (x * 10 + 7) % k;
      count++;
    }
    return count;
  }
};

int main() {
  ll k;
  cin >> k;
  Repsept r7;
  cout << r7.first7(k) << newl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define rep(a, b, c, i) for (int i = a; i < b; i++)
#define ff first
#define ss second
#define newl "\\n"

using namespace std;

class Repsept {
public:
  ll first7(ll k) {
    ll seven = 7;
    ll count = 1;
    if (k % 2 == 0 || k % 5 == 0)
      return -1;
    while (1) {
      if (seven % k == 0)
        break;
      seven = seven * 10 + 7;
      cerr << seven << newl;
      count++;
    }
    return count;
  }
};

int main() {
  ll k;
  cin >> k;
  Repsept r7;
  cout << r7.first7(k) << newl;
}