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

#include <bits/stdc++.h>
using namespace std;
#define INF LONG_LONG_MAX
#define int long long
#define ar array
#define db double
#define pi 3.14159265358979323846
#define pow pw
int pw(int a, int b) {
  int ans = 1;
  while (b) {
    if (b % 2)
      ans *= a;
    a *= a;
    b /= 2;
  }
  return (ans);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int k;
  cin >> k;
  int ans = 0, du = 0;
  do {
    ans++;
    du = (du * 10 + 7) % k;
    if (ans > k) {
      cout << -1;
      return 0;
    }
  } while (du);
  cout << ans;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define INF LONG_LONG_MAX
#define int long long
#define ar array
#define db double
#define pi 3.14159265358979323846
#define pow pw
int pw(int a, int b) {
  int ans = 1;
  while (b) {
    if (b % 2)
      ans *= a;
    a *= a;
    b /= 2;
  }
  return (ans);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int k;
  cin >> k;
  int ans = 0, du = 0;
  do {
    ans++;
    du = (du * 10 + 7) % k;
  } while (du);
  cout << ans;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <cmath>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int, int>> qu2;
priority_queue<int> pq;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i, s, n) for (int i = s; i < n; i++)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
deque<int> deq;
#define fi first
#define se second
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
int main() {
  int k;
  cin >> k;
  ll s = 7;
  ll ans = 1;
  while (1) {
    if (s % k == 0) {
      cout << ans << endl;
      return 0;
    } else {
      s %= k;
      s = s * 10 + 7;
      ans++;
    }
    if (k % 2 == 0) {
      break;
    }
    if (ans > k + 1) {
      break;
    }
  }
  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <cmath>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int, int>> qu2;
priority_queue<int> pq;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i, s, n) for (int i = s; i < n; i++)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
#define Rrep(i, n) Rreps(i, n, 0)
deque<int> deq;
#define fi first
#define se second
// const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
int main() {
  int k;
  cin >> k;
  ll s = 7;
  ll ans = 1;
  while (1) {
    if (s % k == 0) {
      cout << ans << endl;
      return 0;
    } else {
      s %= k;
      s = s * 10 + 7;
      ans++;
    }
    if (k % 2 == 0) {
      break;
    }
    if (ans > INF) {
      break;
    }
  }
  cout << -1 << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
// #define int long long
#define rep(i, l, r) for (int i = l; i <= r; ++i)

inline int read() {
  char cc = getchar();
  int cn(0), flus(1);
  while (cc < '0' || cc > '9') {
    if (cc == '-')
      flus = -flus;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9') {
    cn = cn * 10 + cc - 48;
    cc = getchar();
  }
  return cn * flus;
}

const int MAXN = 1e6 + 10, INF = 2147483647;
const int Mod = 998244353, G = 3;

int n, d;
bool vis[MAXN];

signed main() {
  int k = read();
  //	rep(k, 1, 100010)
  int tmp = 0;
  if (!(k & 1)) {
    printf("-1\\n");
    //		continue;
    return 0;
  }
  int pcs(0);
  while (1) {
    pcs++;
    tmp = tmp * 10 + 7;
    tmp %= k;
    if (vis[tmp]) {
      printf("-1\\n");
      return 0;
    }
    vis[tmp] = 1;
    if (!tmp) {
      printf("%d\\n", pcs);
      //			return 0;
      break;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
// #define int long long
#define rep(i, l, r) for (int i = l; i <= r; ++i)

inline int read() {
  char cc = getchar();
  int cn(0), flus(1);
  while (cc < '0' || cc > '9') {
    if (cc == '-')
      flus = -flus;
    cc = getchar();
  }
  while (cc >= '0' && cc <= '9') {
    cn = cn * 10 + cc - 48;
    cc = getchar();
  }
  return cn * flus;
}

const int MAXN = 1e5 + 10, INF = 2147483647;
const int Mod = 998244353, G = 3;

int n, d;

signed main() {
  int k = read(), tmp(0);
  if (!(k & 1)) {
    printf("-1\\n");
    return 0;
  }
  int pcs(0);
  while (1) {
    pcs++;
    tmp = tmp * 10 + 7;
    tmp %= k;
    if (!tmp) {
      printf("%d\\n", pcs);
      return 0;
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define hs                                                                     \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve() {
  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1";
    return;
  }
  ll k = 7;
  ll cnt = 1;
  while (true) {
    if (k % n == 0) {
      cout << cnt;
      break;
    }
    if (cnt > n) {
      cout << "-1";
      break;
    }
    k = (k % n) * 10 + 7;
    // cout<<k<<"\\n";
    ++cnt;
  }
}
int main() {
  hs;
  ll t;
  t = 1;
  // cin>>t;
  for (int i = 1; i <= t; i++) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <assert.h>
#include <bits/stdc++.h>
#include <cmath>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define for1(x, y) for (long long x = 1; x < ll(y); x++)
#define forn(x, y, z) for (long long x = y; x < ll(z); x++)
#define for0(x, y, z) for (long long x = y; x < ll(z); x++)
#define PII pair<int, int>
#define FF first
#define SS second
#define PB push_back

#define forn(x, y, z) for (long long x = y; x < ll(z); x++)
#define for0(x, y, z) for (long long x = y; x < ll(z); x++)
using namespace std;
typedef long long ll;
typedef long double ld;

#define maxn 1000015
const double EPS = (1e-7), EPSm = (1e7);
const ll linf = (ll)1e17 + 5;
long double PI = 3.14159265359;
int dir[8][2] = {{1, 0},   {-1, 0}, {0, 1},  {0, -1},
                 {-1, -1}, {1, 1},  {-1, 1}, {1, -1}};

const int MAXN = 1e5 + 10;
const int NINF = -1e5;
const int INF = 2000000000;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  setprecision(20);
  int test;
  // cin >> test;
  // while(test--)
  solve();
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  long long int k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
  } else {
    long long int now = 7;
    long long int count = 1;
    while (true) {
      if (now % k == 0) {
        cout << count << endl;
        break;
      } else {
        now *= 10;
        now += 7;
        now %= k;
        count++;
      }
    }
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  long long int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
  } else {
    long long int now = 7;
    long long int count = 1;
    while (true) {
      if (now % k == 0) {
        cout << count << endl;
        break;
      } else {
        now *= 10;
        now += 7;
        now %= k;
        count++;
      }
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <unordered_set>

#define ll long long

using namespace std;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll k;

  cin >> k;

  ll curr = 0;

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

    curr = curr * 10 + 7;
    curr = curr % k;

    if (curr == 0) {
      cout << i << endl;
      return 0;
    }
  }

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


Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <unordered_set>

#define ll long long

using namespace std;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll k;

  cin >> k;

  ll curr = 7;

  ll ans = 1;

  if (k == 2 || k == 5) {
    cout << -1 << endl;
  } else {
    while (curr % k != 0) {

      curr = curr * 10 + 7;
      curr = curr % k;
      ans++;
    }

    cout << ans << endl;
  }

  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  if ((n & 1) == 0 || n % 5 == 0) {
    cout << -1;
    return 0;
  }
  int i = 1;
  int s = 7;
  while (true) {
    s = s % n;
    if (s % n == 0) {
      cout << i;
      return 0;
    }
    i++;
    s = 10 * s + 7;
  }
}


Error: 1

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  if ((n & 1) == 0 || n % 5 == 0) {
    cout << -1;
    return 1;
  }
  int i = 1;
  int s = 7;
  while (true) {
    s = s % n;
    if (s % n == 0) {
      cout << i;
      return 1;
    }
    i++;
    s = 10 * s + 7;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef pair<int, int> P;
struct edge {
  int to, id;
};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007

using graph = vector<vector<ll>>;
int main() {
  ll k;
  cin >> k;
  int count = 1;
  ll hoge;
  hoge = 7 % k;
  bool huga[10000010];
  rep(i, 1000010) { huga[i] = false; }
  if (k % 2 == 0) {
    count = -1;
  } else {
    while (hoge != 0 && count <= k) {
      huga[hoge] = true;
      count++;
      hoge = (hoge * 10 + 7) % k;
      if (huga[hoge]) {
        count = -1;
        break;
      }
    }
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

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

typedef pair<int, int> P;
struct edge {
  int to, id;
};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007

using graph = vector<vector<ll>>;
int main() {
  ll k;
  cin >> k;
  int count = 1;
  ll hoge;
  hoge = 7 % k;
  if (k % 2 == 0) {
    count = -1;
  } else {
    while (hoge != 0) {
      count++;
      hoge = (hoge * 10 + 7) % k;
    }
  }
  cout << count << endl;
}
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 FOR(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T> using arr = vector<vector<T>>;
template <class T> int popcount(T &a) {
  int c = 0;
  rep(i, 8 * (int)sizeof(a)) {
    if ((a >> i) & 1)
      c++;
  }
  return c;
}
template <class T> void pr(T x) { cout << x << endl; }
template <class T> void prvec(vector<T> &a) {
  rep(i, a.size() - 1) { cout << a[i] << " "; }
  pr(a[a.size() - 1]);
}
template <class T> void prarr(arr<T> &a) {
  rep(i, a.size()) if (a[i].empty()) pr("");
  else prvec(a[i]);
}
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;
}

int main() {
  int k;
  cin >> k;
  int ans = 0;
  set<int> loop;
  int loop_init = 7 % k;
  loop.insert(loop_init);
  if (loop_init == 0)
    ans = 1;
  else if (k % 2 == 0)
    ans = -1;
  else {
    int s = 77;
    int cnt = 2;
    int mod = s % k;
    while (1) {
      if (mod == 0) {
        ans = cnt;
        break;
      }
      if (loop.find(mod) != loop.end()) {
        ans = -1;
        break;
      }
      loop.insert(mod);
      mod = (mod * 10 + 7) % k;
      cnt++;
    }
  }
  pr(ans);
  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 FOR(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T> using arr = vector<vector<T>>;
template <class T> int popcount(T &a) {
  int c = 0;
  rep(i, 8 * (int)sizeof(a)) {
    if ((a >> i) & 1)
      c++;
  }
  return c;
}
template <class T> void pr(T x) { cout << x << endl; }
template <class T> void prvec(vector<T> &a) {
  rep(i, a.size() - 1) { cout << a[i] << " "; }
  pr(a[a.size() - 1]);
}
template <class T> void prarr(arr<T> &a) {
  rep(i, a.size()) if (a[i].empty()) pr("");
  else prvec(a[i]);
}
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;
}

int main() {
  int k;
  cin >> k;
  int ans = 0;
  int loop_init = 7 % k;
  if (loop_init == 0)
    ans = 1;
  else if (k % 2 == 0)
    ans = -1;
  else {
    int s = 77;
    int cnt = 2;
    int mod = s % k;
    while (1) {
      if (mod == 0) {
        ans = cnt;
        break;
      }
      if (mod == loop_init) {
        ans = -1;
        break;
      }

      mod = (mod * 10 + 7) % k;
      cnt++;
    }
  }
  pr(ans);
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
bool exist[1000005];

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0)
    cout << -1;
  else {
    int curr = 7 % k;
    int sum = curr;
    int counter = 1;
    exist[sum] = true;
    while (sum % k) {
      curr *= (10 % k);
      curr %= k;
      sum += curr;
      sum %= k;
      if (exist[sum]) {
        cout << -1;
        return 0;
      }
      exist[sum] = true;
      counter++;
    }
    cout << counter;
  }
}

Error: TLE

Fixed submission:

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

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

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

ll K;

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

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

  ll cur = 7 % K;
  ll ans = 1;
  for (;;) {
    if (cur == 0) {
      cout << ans;
      return 0;
    }

    cur = (10 % K) * (cur % K) + 7 % K;
    cur %= K;
    ++ans;

    if (ans > 10000000) {
      cout << -1;
      return 0;
    }
  }
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

ll K;

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

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

  ll cur = 7 % K;
  ll ans = 1;
  for (;;) {
    if (cur == 0) {
      cout << ans;
      return 0;
    }

    cur = (10 % K) * (cur % K) + 7 % K;
    cur %= K;
    ++ans;

    if (ans > 100000000) {
      cout << -1;
      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 prev_a = 7 % k;
  if (prev_a == 0) {
    cout << 1 << endl;
  } else {
    bool done = false;
    for (int i = 2; i <= k; ++i) {
      int curr_a = (prev_a * 10 + 7) % k;
      if (curr_a == 0) {
        done = true;
        cout << i << endl;
        break;
      } else {
        prev_a = curr_a;
      }
    }
    if (!done) {
      cout << -1 << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

int main() {
  int k;
  std::cin >> k;
  int number = 7;
  int count = 0;
  while (number < std::numeric_limits<int>::max()) {
    count++;
    if (number % k == 0) {
      break;
    }
    number = number * 10 + 7;
  }
  if (count == 0) {
    std::cout << -1 << std::endl;
  } else {
    std::cout << count << std::endl;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

// #include<i_am_noob_orz>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ull unsigned long long
#define pii pair<int, int>
#define X first
#define Y second
#define mod ((ll)1e9 + 7)
#define pb push_back
#define mp make_pair
#define abs(x) ((x) > 0 ? (x) : (-(x)))
#define F(n) Fi(i, n)
#define Fi(i, n) Fl(i, 0, n)
#define Fl(i, l, n) for (int i = l; i < n; i++)
#define memres(a) memset(a, 0, sizeof(a))
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
#define ceiling(a, b) (((a) + (b)-1) / (b))
#define endl '\\n'
#define bit_count(x) __builtin_popcount((x))
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #define LOCAL
#ifdef LOCAL
#define debug(a) cerr << #a << " " << a << endl;
#else
#define debug(a)
#endif
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
bool ar[1000010];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, ct = 0, p = 7, s = 0;
  cin >> n;
  bool tag = true;
  while (1) {
    s += p;
    ct++;
    s = s % n;
    if (s == 0)
      break;
    if (ar[s]) {
      tag = false;
      break;
    }
    ar[s] = true;
    p = (p * 10) % n;
  }
  if (tag)
    cout << ct << endl;
  else
    cout << "-1" << endl;
  return 0;
}


Error: TLE

Fixed submission:

// #include<i_am_noob_orz>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ull unsigned long long
#define pii pair<int, int>
#define X first
#define Y second
#define mod ((ll)1e9 + 7)
#define pb push_back
#define mp make_pair
#define abs(x) ((x) > 0 ? (x) : (-(x)))
#define F(n) Fi(i, n)
#define Fi(i, n) Fl(i, 0, n)
#define Fl(i, l, n) for (int i = l; i < n; i++)
#define memres(a) memset(a, 0, sizeof(a))
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
#define ceiling(a, b) (((a) + (b)-1) / (b))
#define endl '\\n'
#define bit_count(x) __builtin_popcount((x))
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #define LOCAL
#ifdef LOCAL
#define debug(a) cerr << #a << " " << a << endl;
#else
#define debug(a)
#endif
int gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
bool ar[1000010];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, ct = 0, p = 7, s = 0;
  cin >> n;
  bool tag = true;
  while (1) {
    s += p;
    ct++;
    s = s % n;
    if (s == 0)
      break;
    if (ar[s]) {
      tag = false;
      break;
    }
    p = (p * 10) % n;
  }
  if (tag)
    cout << ct << endl;
  else
    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;

int main() {
  ll k;
  cin >> k;
  ll x = 7;
  ll ans = 1;
  while (x % k && ans < k + 1) {
    x = (10 * x + 7) % k;
    ans++;
  }
  cout << (ans >= k + 1 ? -1 : ans) << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  scanf("%d", &k);
  set<int> s;
  int x = 7 % k;          // 余り(mod)を使えばtleしない
  int count = 1;          // 割った回数=項数
  while (s.count(x) == 0) // set sの中にxと同じ数字が出るまで繰り返す
  {
    if (x == 0) {            // xが0になったらkの倍数がある
      printf("%d\\n", count); // countが項数
      return 0;
    }
    s.insert(x);          // setに入れる
    x = (x * 10 + 7) % k; // 次のxを作る。7,77,777の配列aはa[x]=a[x - 1] * 10 +
                          // 7。余りの配列でも求め方は一緒。
    count++;
  }
  printf("-1\\n");
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int k;
  scanf("%d", &k);
  int count = 1;
  if (k % 2 == 0) {
    printf("-1\\n");
    return 0;
  } else {
    ll digit = 7;
    while (digit % k != 0) {
      digit = (digit * 10) + 7;
      count++;
    }
  }
  printf("%d\\n", count);
  return 0;
}