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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll, ll>;
const ll mod = 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REPS(i, n) for (ll(i) = 1; (i) <= (n); (i)++)
#define RREP(i, n) for (ll(i) = (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for (ll(i) = (n); (i) > 0; (i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

template <class T> inline void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

template <class T> inline void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  ll K;
  cin >> K;
  if (K % 7 == 0)
    K /= 7;
  ll asd = 1;
  ll bef = 1;
  ll count = 1;
  if (K % 2 == 0 || K % 5 == 0) {
    count = -1;
  } else {
    while (1) {
      if (asd % K == 0)
        break;
      count++;
      bef = bef * 10 % K;
      asd += bef;
    }
  }
  cout << count << "\\n";
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll, ll>;
const ll mod = 1e9 + 7;
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define REPS(i, n) for (ll(i) = 1; (i) <= (n); (i)++)
#define RREP(i, n) for (ll(i) = (n - 1); (i) >= 0; (i)--)
#define RREPS(i, n) for (ll(i) = (n); (i) > 0; (i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

template <class T> inline void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}

template <class T> inline void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  ll K;
  cin >> K;
  ll asd = 1;
  ll bef = 1;
  ll count = 1;
  if (K != 2 && K != 5) {
    while (1) {
      if (asd * 7 % K == 0)
        break;
      count++;
      bef = bef * 10 % K;
      asd += bef;
    }
  } else {
    count = -1;
  }
  cout << count << "\\n";
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
int main() {

  ll k;
  cin >> k;
  if (k % 7 == 0)
    k /= 7;

  if ((k % 2 == 0) || ((k % 5) == 0))
    printf("-1");
  else {
    ll i = 1, power = 10;
    if (k == 1)
      printf("1");

    else if (k % 9 == 0) {
      while (power != 1) {
        i++;
        power *= 10;
        power %= (9 * k);
      }
      printf("%lld", i);
    } else if (k % 3 == 0) {
      while (power != 1) {
        i++;
        power *= 10;
        power %= (9 * k);
      }
      printf("%lld", i);
    } else {
      while (power != 1) {
        i++;
        power *= 10;
        power %= (9 * k);
      }
      printf("%lld", i);
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
int main() {

  ll k;
  cin >> k;
  if (k % 7 == 0)
    k /= 7;

  if ((k % 2 == 0) || (k % 5) == 0)
    printf("-1");
  else {
    ll i = 1, power = 10;
    if (k % 9 == 0) {
      while (power != 1) {
        i++;
        power *= 10;
        power %= (9 * k);
      }
      printf("%lld", i);
    } else if (k % 3 == 0) {
      while (power != 1) {
        i++;
        power *= 10;
        power %= (9 * k);
      }
      printf("%lld", i);
    } else {
      while (power != 1) {
        i++;
        power *= 10;
        power %= k;
      }
      printf("%lld", i);
    }
  }

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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll k;
  cin >> k;

  map<ll, ll> mp;
  if (k % 2 == 0) {
    cout << -1 << endl;
  } else {
    ll num = 7;
    ll index = 1;
    while (1) {
      num %= k;
      if (mp[num] != 0) {
        cout << -1 << endl;
        break;
      }
      mp[num]++;
      if (num == 0) {
        cout << index << endl;
        break;
      }
      while (num <= k) {
        num = num * 10 + 7;
        index++;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define ll long long
using namespace std;
const int MOD = 1000000007;
const long long INF = 1LL << 60;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll num = 7;
  ll index = 1;
  while (1) {
    num %= k;
    if (num == 0) {
      cout << index << endl;
      return 0;
    }
    while (num <= k) {
      num = num * 10 + 7;
      index++;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long seven = 0;
  long K;
  cin >> K;
  for (long i = 1; i < 1000000; i++) {
    seven = 10 * seven + 7;
    seven %= K;
    if (seven == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long seven = 0;
  long K;
  long i = 1;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (true) {
    seven = 10 * seven + 7;
    seven %= K;
    if (seven == 0) {
      cout << i << endl;
      break;
    }
    i++;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll k;
set<int> s;
ll bm(ll a, ll b) {
  if (b == 0)
    return 1;
  ll t = bm(a, b / 2);
  if (b % 2 == 0)
    return t * t % k;
  else
    return a * (t * t % k) % k;
}
int main() {
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  if (k % 7 == 0)
    k /= 7;
  k *= 9;
  ll i = 1;
  while (i) {
    ll now = bm(10, i);
    if (s.count(now)) {
      cout << "-1" << endl;
      return 0;
    }
    if (now == 1) {
      cout << i << endl;
      return 0;
    }
    s.insert(now);
    i++;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n % 2 == 0) {
    cout << -1;
  } else {
    for (int i = 1; i < 20; i++) {
      string s(i, '7');
      int p = stoi(s);
      if (p % n == 0) {
        cout << i;
        return 0;
      };
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll k;
  ll count = 0;
  ll amount = 0;
  ll ans = -1;
  cin >> k;
  if (k % 2 == 0) {
    cout << ans << endl;
  } else {
    rep(i, 1e7) {
      amount *= 10;
      amount += 7;
      count++;
      if (amount % k == 0) {
        ans = count;
        break;
      } else {
        amount = amount % k;
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  ll k;
  ll count = 0;
  ll amount = 0;
  ll ans = -1;
  cin >> k;
  if (k % 2 == 0) {
    cout << ans << endl;
  } else {
    for (;;) {
      amount *= 10;
      amount += 7;
      count++;
      if (amount % k == 0) {
        ans = count;
        break;
      } else {
        amount = amount % k;
      }
    }
    cout << ans << endl;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n;
  int m = 7;
  cin >> n;
  if (n % 10 == 0 || n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 6 ||
      n % 10 == 8) {
    cout << -1 << endl;
    return 0;
  }
  vector<bool> a(n);
  for (int i = 0; i < 100000000; i++) {
    if (m % n == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    if (a.at(m % n - 1) == true) {
      cout << -1 << endl;
      return 0;
    }
    a.at(m % n - 1) = true;
    m = (m * 10 + 7) % n;
  }
  cout << -1 << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int n;
  int m = 7;
  cin >> n;
  if (n % 10 == 0 || n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 6 ||
      n % 10 == 8) {
    cout << -1 << endl;
  }
  vector<bool> a(n);
  for (int i = 0; i < 100000000; i++) {
    if (m == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    if (a.at(m - 1) == true) {
      cout << -1 << endl;
      return 0;
    }
    a.at(m - 1) = true;
    m = (m * 10 + 7) % n;
  }
  cout << -1 << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000000000009;
#define WARU 1000000007;

using namespace std;
int gcd(int a, int b) {
  while (a % b != 0) {
    int c = 0;
    c = a % b;
    a = b;
    b = c;
  }
  return b;
}

int main() {
  int N = 0;
  // bool ok = false;
  long long a[100005], K = 0, ans = 1, amari = 0, memo = 0;
  cin >> K;
  if (K % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  amari = 7 % K;
  while (amari != 0 && ans < K + 10) {
    amari = 7 + (amari * 10) % K;
    amari = amari % K;
    // cout << amari << endl;
    ans++;
  }
  if (ans == K + 10) {
    cout << "-1" << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000000000009;
#define WARU 1000000007;

using namespace std;
int gcd(int a, int b) {
  while (a % b != 0) {
    int c = 0;
    c = a % b;
    a = b;
    b = c;
  }
  return b;
}

int main() {
  int N = 0;
  // bool ok = false;
  long long a[100005], K = 0, ans = 1, amari = 0, memo = 0;
  cin >> K;
  if (K % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  amari = 7 % K;
  while (amari != 0) {
    amari = 7 + (amari * 10) % K;
    amari = amari % K;
    // cout << amari << endl;
    ans++;
  }
  cout << ans << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main(void) {
  u64 K;
  cin >> K;

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

  u64 t = 7;
  u64 l = 1;
  vector<bool> his(K);

  while (!his[t % K]) {
    if (t % K == 0) {
      cout << l << endl;
      return 0;
    }

    his[t % K] = true;
    l++;
    t = (t % K) * 10 + 7;
  }

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

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main(void) {
  u64 K;
  cin >> K;

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

  u64 t = 7;
  u64 l = 1;
  vector<bool> his(max((u64)8, K));

  while (!his[t]) {
    if (t % K == 0) {
      cout << l << endl;
      return 0;
    }

    his[t] = true;
    l++;
    t = (t % K) * 10 + 7;
  }

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

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX >> 2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i, a, n, x) for ((i) = (a); (i) < (n); (i) += (x))
#define fd(i, a, n, x) for ((i) = (a); (i) >= (n); (i) -= (x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
#define ms multiset
using namespace std;
void read(vt<ll> &a, ll n) {
  ll i, temp;
  f(i, 0, n, 1) {
    cin >> temp;
    a.pb(temp);
  }
}
ll fa[MAX];
ll power(ll p, ll q) {
  ll res = 1;
  p %= mod;
  while (q) {
    if (q & 1)
      res = (res * p) % mod;
    q >>= 1;
    p = (p * p) % mod;
  }
  return res;
}
ll fact(ll n) {
  if (n <= 1)
    return fa[n] = 1;
  if (fa[n])
    return fa[n];
  return fa[n] = (n * fact(n - 1)) % mod;
}
ll ncr(ll n, ll r) {
  if (!r)
    return 1;
  return (((fact(n) * power(fact(n - r), mod - 2)) % mod) *
          power(fact(r), mod - 2)) %
         mod;
}
void solve() {
  ll n = 7, k, count = 1;
  cin >> k;
  while (count <= 10000000) {
    if (!(n % k)) {
      cout << count << endl;
      return;
    }
    n = (((n % k) * 10) % k + 7) % k;
    count++;
  }
  cout << -1 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX >> 2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i, a, n, x) for ((i) = (a); (i) < (n); (i) += (x))
#define fd(i, a, n, x) for ((i) = (a); (i) >= (n); (i) -= (x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
#define ms multiset
using namespace std;
void read(vt<ll> &a, ll n) {
  ll i, temp;
  f(i, 0, n, 1) {
    cin >> temp;
    a.pb(temp);
  }
}
ll fa[MAX];
ll power(ll p, ll q) {
  ll res = 1;
  p %= mod;
  while (q) {
    if (q & 1)
      res = (res * p) % mod;
    q >>= 1;
    p = (p * p) % mod;
  }
  return res;
}
ll fact(ll n) {
  if (n <= 1)
    return fa[n] = 1;
  if (fa[n])
    return fa[n];
  return fa[n] = (n * fact(n - 1)) % mod;
}
ll ncr(ll n, ll r) {
  if (!r)
    return 1;
  return (((fact(n) * power(fact(n - r), mod - 2)) % mod) *
          power(fact(r), mod - 2)) %
         mod;
}
void solve() {
  ll n = 7, k, count = 1;
  cin >> k;
  while (count <= 100000000) {
    if (!(n % k)) {
      cout << count << endl;
      return;
    }
    n = (((n % k) * 10) % k + 7) % k;
    count++;
  }
  cout << -1 << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin>>t;
  while (t--)
    solve();
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>   //abs()かfabs()で少数絶対値
#include <cstdlib> //abs()で整数絶対値
#include <deque>
#include <functional> //sort第三引数greater<型名>()で降順
#include <iomanip>    //cout<<setw(数字) で空白による桁揃え
#include <iostream>   //cout<<right で右揃え
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

int main() {
  int K;
  cin >> K;
  vector<int> A(K + 1);
  A[1] = 7 % K;
  for (int i = 2; i <= K; i++)
    A[i] = (A[i - 1] * 10 + 7) % K;
  for (int i = 1; i <= K; i++) {
    if (A[i] == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>   //abs()かfabs()で少数絶対値
#include <cstdlib> //abs()で整数絶対値
#include <deque>
#include <functional> //sort第三引数greater<型名>()で降順
#include <iomanip>    //cout<<setw(数字) で空白による桁揃え
#include <iostream>   //cout<<right で右揃え
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

ll mod_pow(ll a, ll index, ll divider) {
  ll ret = 1;
  for (; index > 0; index /= 2, a = a * a % divider) {
    if (index % 2 == 1) {
      ret = ret * a % divider;
    }
  }
  return ret;
}

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

#include <iostream>
using namespace std;

int main(void) {
  int k, md, i;
  char flg[1000000] = {0};

  cin >> k;
  i = 1;
  if ((md = 7 % k) == 0) {
    cout << i << endl;
    return 0;
  }
  flg[md] = 1;
  while (i++) {
    md = (md * 10 + 7) % k;
    if (md == 0) {
      cout << i << endl;
      break;
    } else if (flg[md]) {
      cout << -1 << endl;
      break;
    }
    flg[md] = 1;
    // cout << md << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int k, md, i;

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

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

int main() {
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll seven = 7;
  ll count = 1;
  while (true) {
    if (seven % k == 0) {
      cout << count << endl;
      return 0;
    }
    seven *= 10;
    seven += 7;
    seven %= k;
    count++;
    if (count > k) {
      cout << -1 << endl;
      return 0;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

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

/////////////////////////////////TEST CASES////////////////////////////////////
/*

*/
/////////////////////////////////////CODE/////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a; i > b; i--)
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define VL vector<ll>
#define IN(inp)                                                                \\
  ll inp;                                                                      \\
  cin >> inp;
#define pb push_back
#define all(a) a.begin(), a.end()
#define what(A) cout << #A << " is " << A << endl;
ll MAX = 1000000000;
ll MOD = 1000000007;
int main() {
  fastio
      // freopen("input.txt", "rt", stdin);
      // freopen("output.txt", "wt", stdout);
      ll test = 1;
  // cin>>test;
  while (test--) {
    IN(n);
    ll k = n % 10;
    if (k == 1 || k == 3 || k == 7 || k == 9) {
      ll t = 7, cnt = 1;
      while (t % n != 0) {
        t *= 10;
        t += 7;
        t %= n;
        cnt++;
        // cout<<t<<endl;
        if (cnt > n) {
          cout << -1 << endl;
          return 0;
        }
      }
      cout << cnt << endl;
    } else
      cout << -1;
  }
}

Error: TLE

Fixed submission:

/////////////////////////////////TEST CASES////////////////////////////////////
/*

*/
/////////////////////////////////////CODE/////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a; i > b; i--)
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define VL vector<ll>
#define IN(inp)                                                                \\
  ll inp;                                                                      \\
  cin >> inp;
#define pb push_back
#define all(a) a.begin(), a.end()
#define what(A) cout << #A << " is " << A << endl;
ll MAX = 1000000000;
ll MOD = 1000000007;
int main() {
  fastio
      // freopen("input.txt", "rt", stdin);
      // freopen("output.txt", "wt", stdout);
      ll test = 1;
  // cin>>test;
  while (test--) {
    IN(n);
    ll k = n % 10;
    if (k == 1 || k == 3 || k == 7 || k == 9) {
      ll t = 7, cnt = 1;
      while (t % n != 0) {
        t *= 10;
        t += 7;
        cnt++;
      }
      cout << cnt << endl;
    } else
      cout << -1;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll k, ans = 1;
  cin >> k;
  int seven = 7;
  if (k % 2 == 0) {
    cout << "-1";
    return 0;
  }
  while (seven % k != 0) {
    seven = (seven * 10 + 7) % k;
    ans++;
    if (ans > 1000000) {
      cout << "-1";
      return 0;
    }
  }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  ll k, ans = 1;
  cin >> k;
  int seven = 7;
  if (k % 2 == 0) {
    cout << "-1";
    return 0;
  }
  while (seven % k != 0) {
    seven = (seven * 10 + 7) % k;
    ans++;
  }
  cout << ans;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  int check = 0;
  string a = "7";
  if (n % 2 == 0) {
    cout << -1;
    check = 1;
  }
  long long num = 7;

  for (int i = 1; i <= 2 * 1000000; i++) {

    // cout<<num<<endl;
    // cout<< num<<endl;
    if (num % n == 0) {
      check = 1;
      cout << i;
      break;
    }
    num = (num * 10 + 7) % n;
  }
  if (check == 0)
    cout << -1;
}


Error: 4

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  string a = "7";
  if (n % 2 == 0)
    return -1;
  if (n % 7 == 0)
    return 1;
  long long num = 7;
  int check = 0;
  for (int i = 2; i <= 1000000; i++) {

    num = (num * 10 + 7) % n;
    // cout<<num<<endl;
    // cout<< num<<endl;
    if (num % n == 0) {
      check = 1;
      return i;
    }
  }

  return -1;
}