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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf = 1000000000000000000, mod = 1000000007, BS, k;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll n;
  cin >> n;
  if (n % 5 == 0) {
    cout << "-1";
    return 0;
  }
  if (n % 2 == 0) {
    cout << "-1";
  } else {
    ll sum = 0, curr = 7;
    while (1) {
      if (curr % n == 0) {
        break;
      }
      curr = (curr * 10) % n;
      curr = (curr + 7) % n;
      sum++;
    }
    std::cout << sum + 1 << "\\n";
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf = 1000000000000000000, mod = 1000000007, BS, k;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1";
  } else {
    ll sum = 0, curr = 7;
    while (1) {
      if (curr % n == 0) {
        break;
      }
      curr = (curr * 10) % n;
      curr = (curr + 7) % n;
      sum++;
    }
    std::cout << sum + 1 << "\\n";
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k;
char c[1000005];
int main() {
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1;
    return 0;
  }
  int cur = 7 % k;
  int ans = 1;
  while (cur != 0) {
    cur = cur * 10 + 7;
    cur %= k;
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

#define int long long

int32_t main() {
  int k;
  cin >> k;
  if (k % 7 == 0) {
    k /= 7;
  }
  if (k == 1) {
    cout << 1 << endl;
    return 0;
  }
  int now = 1;
  map<int, int> mp;
  mp[1] = 1;
  int ans = 1;
  while (1) {
    now = now * 10 + 1;
    now %= k;
    // cout << now << endl;
    if (mp.find(now) != mp.end()) {
      break;
    }
    mp[now] = ++ans;
  }
  if (mp.find(0) != mp.end())
    cout << mp[0] << endl;
  else
    cout << -1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

#define int long long

int32_t main() {
  int k;
  cin >> k;
  if (k % 7 == 0) {
    k /= 7;
  }
  if (k == 1) {
    cout << 1 << endl;
    return 0;
  }

  vector<int> rem;
  rem.push_back(1 % k);
  int newi;
  while (1) {
    newi = (rem.back() * 10 + 1) % k;
    rem.push_back(newi);
    if (newi == 1 || newi == 0) {
      break;
    }
  }

  int ans = -1;

  for (int i = 0; i < rem.size(); i++) {
    if ((rem[i]) % k == 0) {
      ans = i + 1;
      break;
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
#include <cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll>
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for (ll i = 0; i < n; i++)
#define forr1(i, n) for (ll i = 1; i <= n; i++)
using namespace std;
const ld PI = 3.1415926535897923846;
const ll MOD = 1000000007;
const ll N = 998244353;
ll power(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
ll modinverse(ll a) { return power(a, MOD - 2); }
void solve() {
  ll k;
  cin >> k;
  ll rem = 0;
  ll pow_of_ten = 1;
  map<ll, ll> mp1;
  for (ll i = 1;; i++) {
    rem = (7 * pow_of_ten) % k + rem;
    rem %= k;
    pow_of_ten = pow_of_ten * 10;
    pow_of_ten %= k;
    if (rem && mp1.find(rem) != mp1.end()) {
      cout << -1 << endl;
      return;
    }
    mp1[rem]++;
    if (rem == 0) {
      cout << i << endl;
      return;
    }
  }
}
int main() {
  ll test = 1;
  while (test--) {
    solve();
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll>
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for (ll i = 0; i < n; i++)
#define forr1(i, n) for (ll i = 1; i <= n; i++)
using namespace std;
const ld PI = 3.1415926535897923846;
const ll MOD = 1000000007;
const ll N = 998244353;
ll power(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
ll modinverse(ll a) { return power(a, MOD - 2); }
void solve() {
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
  }
  ll rem = 0;
  ll pow_of_ten = 1;
  for (ll i = 1;; i++) {
    rem = (7 * pow_of_ten) % k + rem;
    rem %= k;
    pow_of_ten = pow_of_ten * 10;
    pow_of_ten %= k;
    if (rem == 0) {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
}
int main() {
  ll test = 1;
  // cin>>test;
  while (test--) {
    solve();
  }
  // cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC <<
  // "ms\\n";
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  ll k;
  cin >> k;
  ll mod = 9 * k;
  if (k % 2 == 0 || k % 5 == 0)
    cout << "-1\\n";
  else {
    ll init = 70;
    init = init % mod;
    ll cnt = 1;
    while (init != 7) {
      // cout << init << "\\n";
      cnt++;
      init = (init * 10) % mod;
    }
    cout << cnt << "\\n";
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  ll k;
  cin >> k;
  ll mod = 9 * k;
  if (k % 2 == 0 && k % 5 == 0)
    cout << "-1\\n";
  else {
    ll init = 70;
    ll cnt = 1;
    while (1) {
      init = (init * 10) % mod;
      cnt++;
    }
    cout << cnt << "\\n";
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  int k, a = 7, sol = 1;
  cin >> k;

  int x = 7 % k;

  for (int i = 1; i <= k; i++) {
    if (x == 0) {
      cout << i;
      return 0;
    }
    x = (x * 10 + 7) % k;
  }

  cout << -1;
  return 0;
}

Error: TLE

Fixed submission:

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

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

  int k, a = 7, sol = 1;
  cin >> k;

  while (1) {
    if (a % k == 0) {
      cout << sol;
      return 0;
    }

    else {
      a = a * 10 + 7;
      sol++;
    }
  }
  cout << -1 << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(), (v).end()
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;
}
const ll INF = 1LL << 60;
const int inf = (1 << 30) - 1;
const int mod = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll t = 7;
  int cnt = 1;
  while (t % k != 0) {
    t = (t * 10 + 7) % k;
    cnt++;
  }
  cout << cnt << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m; i >= n; --i)
#define ALL(v) (v).begin(), (v).end()
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;
}
const ll INF = 1LL << 60;
const int inf = (1 << 30) - 1;
const int mod = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k;
  cin >> k;
  if (k == 2 || k == 5) {
    cout << -1 << endl;
    return 0;
  }
  ll t = 7;
  int cnt = 1;
  while (t % k != 0) {
    t = (t * 10 + 7) % k;
    cnt++;
  }
  cout << cnt << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int k;
  cin >> k;
  if ((k % 2) == 0 || (k % 5) == 0)
    cout << -1 << endl;
  else if (k == 1 || k == 7)
    cout << 1 << endl;
  else {
    if ((k % 7) == 0)
      k /= 7;
    vector<int> x(0);
    x.push_back(1 % k);
    while (1) {
      int X = (10 * x.at(x.size() - 1)) % k;
      if (X == 1)
        break;
      x.push_back(X);
    }
    int c = 0, m = 0;
    bool b = 0;
    while (1) {
      for (int X : x) {
        c++;
        m += X;
        m = m % k;
        if (m == 0) {
          b = 1;
          break;
        }
      }
      if (b)
        break;
    }
    cout << c << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int k;
  cin >> k;
  if ((k % 2) == 0 || (k % 5) == 0)
    cout << -1 << endl;
  else if (k == 1)
    cout << 1 << endl;
  else {
    if ((k % 7) == 0)
      k /= 7;
    vector<int> x(0);
    x.push_back(1 % k);
    while (1) {
      int X = (10 * x.at(x.size() - 1)) % k;
      if (X == 1)
        break;
      x.push_back(X);
    }
    int c = 0, m = 0;
    bool b = 0;
    while (1) {
      for (int X : x) {
        c++;
        m += X;
        m = m % k;
        if (m == 0) {
          b = 1;
          break;
        }
      }
      if (b)
        break;
    }
    cout << c << endl;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const int maxn = 1e6 + 5;
int flag[maxn];

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

  int num;
  cin >> num;
  int index = (7 % num);
  int count = 1;

  if (!(num % 2)) {
    cout << "-1" << endl;
  } else {

    // 77%13

    while (index != 0 && flag[index] == 0) {

      flag[index] = 1;
      int temp = index;
      index = ((temp * 10) % num + 7 % num) % num;
      // cout<<index<<endl;
      count++;
    }

    if (index != 0 && flag[index] == 1)
      cout << "-1" << endl;
    else
      cout << count << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

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

  int num;
  cin >> num;
  int index = (7 % num);
  int count = 1;

  if (!num % 2) {
    cout << "-1" << endl;
  } else {
    while (index != 0) {
      int temp = index;
      index = (temp * 10 + 7) % num;
      count++;
    }
    cout << count << endl;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

#define fastio() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

void go() {
  int k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << "-1";
    return;
  }
  int track = 0, ans = -1;
  for (int i = 0;; i++) {
    track = (track * 10 + 7) % k;
    if (track == 0) {
      ans = i + 1;
      break;
    }
  }
  cout << ans;
}
int main() {
  fastio();
  go();

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

#define fastio() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

void go() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1";
    return;
  }
  int track = 0, ans = -1;
  for (int i = 0;; i++) {
    track = (track * 10 + 7) % k;
    if (track == 0) {
      ans = i + 1;
      break;
    }
  }
  cout << ans;
}
int main() {
  fastio();
  go();

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

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

#define ll long long int
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vl>
#define vvi vector<vi>
#define pb push_back
#define P pair<ll, ll>
#define mp make_pair
#define F first
#define S second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Sort(v) sort(v.begin(), v.end())
#define all(v) v.begin(), v.end()

ll mo = 1000000007;
ll MO = 998244353;

ll modpower(ll a, ll b, ll mod) {
  ll ans = 1;
  if (b == 0) {
    return 1;
  }
  if (b % 2 == 1) {
    ans = a;
  }
  ll x = modpower(a, b / 2, mod) % mod;
  ans *= (x * x) % mod;
  ans %= mod;
  return ans;
}

void pri(vl a) {
  for (auto i : a)
    cout << i << " ";
  cout << endl;
}

//-------------------------------------------------------------------------------

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int nt = 1;
  // cin>>nt;
  while (nt--) {
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

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

#define ll long long int
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vl>
#define vvi vector<vi>
#define pb push_back
#define P pair<ll, ll>
#define mp make_pair
#define F first
#define S second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Sort(v) sort(v.begin(), v.end())
#define all(v) v.begin(), v.end()

ll mo = 1000000007;
ll MO = 998244353;

ll modpower(ll a, ll b, ll mod) {
  ll ans = 1;
  if (b == 0) {
    return 1;
  }
  if (b % 2 == 1) {
    ans = a;
  }
  ll x = modpower(a, b / 2, mod) % mod;
  ans *= (x * x) % mod;
  ans %= mod;
  return ans;
}

void pri(vl a) {
  for (auto i : a)
    cout << i << " ";
  cout << endl;
}

//-------------------------------------------------------------------------------

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  int nt = 1;
  // cin>>nt;
  while (nt--) {
    solve();
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  ll n, x = 7, ans = 1;
  cin >> n;
  if ((n % 2) == 0) {
    cout << "-1\\n";
    return 0;
  }
  while (true) {
    if ((x % n) == 0) {
      cout << ans << '\\n';
      return 0;
    }
    x *= 10;
    x += 7;
    x %= n;
    ans++;
    if (ans > 1000001) {
      cout << -1 << '\\n';
      return 0;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  ll n, x = 7, ans = 1;
  cin >> n;
  if ((n % 2) == 0) {
    cout << "-1\\n";
    return 0;
  }
  while (true) {
    if ((x % n) == 0) {
      cout << ans << '\\n';
      return 0;
    }
    x *= 10;
    x += 7;
    x %= n;
    ans++;
  }
}
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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(), i.end()
using namespace std;
const long long INF = 1e9 + 7;
const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
// const ll MOD=998244353LL;
// const ll MOD=1777777777LL;

int main() {
  ll N;
  cin >> N;
  ll d[N];
  ll ans = -1;
  d[0] = 7 % N;
  rep(i, N) {
    if (N % 2 == 0)
      break;
    if (d[i] == 0) {
      ans = i + 1;
      break;
    } else {
      d[i + 1] = (d[i] * 10 + 7) % N;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(), i.end()
using namespace std;
const long long INF = 1e9 + 7;
const string alp = "abcdefghijklmnopqrstuvwxyz"; // 26
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
// const ll MOD=998244353LL;
// const ll MOD=1777777777LL;

int main() {
  ll N;
  cin >> N;
  ll d[1000000];
  ll ans = -1;
  d[0] = 7 % N;
  rep(i, 1000000) {
    if (N % 2 == 0)
      break;
    if (N == 7) {
      ans = 1;
      break;
    }
    if (N == 1) {
      ans = 1;
      break;
    }
    if (d[i] == 0) {
      ans = i + 1;
      break;
    } else {
      d[i + 1] = (d[i] * 10 + 7) % N;
    }
  }
  cout << ans << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll k;
  cin >> k;
  ll n = 7, ans = 1;

  rep(i, 1000000) {
    if (n % k == 0) {
      cout << ans << endl;
      return 0;
    }
    ans++;
    n = (10 * n + 7) % k;
  }
  cout << -1 << endl;
}

Error: TLE

Fixed submission:

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

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n = 7, k, count = 1;
  cin >> k;
  while (n % k) {
    n = (n % k) * 10 + 7;
    count++;
    if (count >= 1000000) {
      count = -1;
      break;
    }
  }
  cout << count;
  return 0;
}

Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>

#define ll long long
#define rep(A, B, C) for (A = B; A < C; ++A)
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

/////////////////////////////////////////////////////

ll K;

ll i, j, k;

int main() {
  scanf("%lld", &K);
  if (K % 2 == 0 || K % 5 == 0) {
    printf("-1\\n");
    return 0;
  }
  i = 0;
  do {
    (k = k * 10 + 7) %= K;
    ++i;
  } while (k);
  printf("%lld\\n", i);
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define ll long long
#define rep(A, B, C) for (A = B; A < C; ++A)
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

/////////////////////////////////////////////////////

ll K;

ll i, j, k;

int main() {
  scanf("%lld", &K);
  if (K % 2 == 0) {
    printf("-1\\n");
    return 0;
  }
  i = 0;
  do {
    (k = k * 10 + 7) %= K;
    ++i;
  } while (k);
  printf("%lld\\n", i);
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int k, ans = -1;
  int s = 0;
  cin >> k;

  for (int i = 1; i <= k; i++) {
    s = (s * 10 + 7) % k;

    if (s == 0) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int k, ans = -1;
  unsigned long long s = 7;
  cin >> k;

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

  for (unsigned long long i = 1; i < ULLONG_MAX; i++) {
    if (s % k == 0) {
      ans = i;
      break;
    }

    s = s * 10 + 7;
  }

  cout << ans << endl;

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

#ifdef DEBUG

#else

#pragma GCC optimize("O3,no-stack-protector")
#pragma GCC optimize("unroll-loops")

#if __cplusplus < 201703L
#pragma GCC target("avx")
#else
#pragma GCC target("avx2")
#endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 999999999999971;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) { return (a - (a % b)) / b; }

Int Ceil(Int a, Int b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return Floor(a, b) + 1;
  }
}

Int digits(Int n) { return (Int)to_string(n).size(); }

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

  Int k;
  cin >> k;

  if (k & 1) {
    Int a = 0;
    Int ans = 0;

    set<Int> s;
    do {
      ans++;
      a = a * 10 + 7;
      a %= k;

      if (s.count(a) == 1) {
        cout << -1 << endl;
        return 0;
      }
      s.insert(a);
    } while (a != 0);

    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#ifdef DEBUG

#else

#pragma GCC optimize("O3,no-stack-protector")
#pragma GCC optimize("unroll-loops")

#if __cplusplus < 201703L
#pragma GCC target("avx")
#else
#pragma GCC target("avx2")
#endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 999999999999971;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) { return (a - (a % b)) / b; }

Int Ceil(Int a, Int b) {
  if (a % b == 0) {
    return a / b;
  } else {
    return Floor(a, b) + 1;
  }
}

Int digits(Int n) { return (Int)to_string(n).size(); }

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

  Int k;
  cin >> k;

  if (k & 1) {
    Int a = 0;
    Int ans = 0;
    do {
      ans++;
      a = a * 10 + 7;
      a %= k;
    } while (a != 0);

    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}