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

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main() {
  int k;
  cin >> k;
  set<int> st;
  ll cnt = 1;
  ll sum = 7 % k;
  st.insert(sum);
  int f = 1;
  while (sum != 0) {
    sum = (10LL * sum + 7) % k;
    cnt++;
    if (st.count(sum) > 0) {
      f = 0;
      break;
    }
    st.insert(sum);
  }
  if (!f)
    cout << "-1\\n";
  else
    cout << cnt << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main() {
  int k;
  cin >> k;
  unordered_set<int> st;
  ll cnt = 1;
  int sum = 7 % k;
  st.insert(sum);
  int f = 1;
  while (sum % k != 0) {
    sum = (10 * sum + 7) % k;
    cnt++;
    if (sum != 0 && st.count(sum)) {
      f = 0;
      break;
    }
  }
  if (!f)
    cout << "-1\\n";
  else
    cout << cnt << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long k;

  cin >> k;

  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
  } else {
    long l, r;
    int i;

    if (k % 7 == 0) {
      l = 9 * k / 7;
    } else {
      l = 9 * k;
    }
    r = 10 % l;

    for (i = 0; r != 1; i++) {
      r = (10 * r) % l;
    }

    cout << i + 1 << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  long k;

  cin >> k;

  if (k % 2 == 0 || k & 5 == 0) {
    cout << -1 << endl;
  } else {
    long l, r = 10 % l;
    int i;
    if (k % 7 == 0) {
      l = 9 * k / 7;
    } else {
      l = 9 * k;
    }
    for (i = 0; r != 1; i++) {
      r = (10 * r) % l;
    }
    cout << i + 1 << endl;
  }

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

#include <iostream>
using namespace std;
int main() {
  long long n;
  cin >> n;
  if (n % 2 == 0 or n % 5 == 0)
    cout << "-1\\n";
  else {
    long long f(0), a(7);
    while (true) {
      a %= n;
      f++;
      if (a == 0) {
        cout << f << endl;
        break;
      }
      a *= 10;
      a += 7;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long n;
  cin >> n;
  if (n % 2 == 0 or n % 5 == 0)
    cout << "-1\\n";
  else {
    long long f(0), a(7);
    while (true) {
      a %= n;
      f++;
      if (a == 0)
        cout << f << endl;
      a *= 10;
      a += 7;
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++) // n回繰り返す
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define REP(i, n) for (int i = 1; i <= (int)n; i++) // i=1からi=nまで
#define RREP(i, n) for (int i = n; i >= 1; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
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;
}

int main() {
  int k;
  cin >> k;
  int s = 7, ans = 1;
  if (k % 2 == 0) {
    cout << -1 << endl;
  }

  else {

    while (ans <= k) {
      if (s % k == 0) {
        cout << ans << endl;
        break;
      } else {
        s = s % k;
        s = s * 10 + 7;
        ans++;
      }
    }
  }
  if (ans == k + 1) {
    cout << -1 << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++) // n回繰り返す
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define REP(i, n) for (int i = 1; i <= (int)n; i++) // i=1からi=nまで
#define RREP(i, n) for (int i = n; i >= 1; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
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;
}

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

/******************
 *AUTHOR: speckrel*
 ******************/

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

#define ll long long

// Function to read int array
void read(ll arr[], ll n) {
  for (ll i = 0; i < n; i++) {
    cin >> arr[i];
  }
}

void solve() {
  static int i = 1;
  // cout<<"This is a test code "<<i<<"\\n";
  i++;
}

int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll k;
  cin >> k;
  ll ans = 1;
  ll rem = 7 % k;
  while (rem) {
    rem = (10 * rem + 7) % k;
    ans++;
    if (ans > 1000000) {
      ans = -1;
      break;
    }
  }
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

/******************
 *AUTHOR: speckrel*
 ******************/

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

#define ll long long

// Function to read int array
void read(ll arr[], ll n) {
  for (ll i = 0; i < n; i++) {
    cin >> arr[i];
  }
}

void solve() {
  static int i = 1;
  // cout<<"This is a test code "<<i<<"\\n";
  i++;
}

int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll k;
  ll ans = 1;
  ll rem = 7 % k;
  while (rem) {
    rem = (10 * rem + 7) % 7;
    ans++;
    if (ans > 1000000) {
      ans = -1;
      break;
    }
  }
  cout << ans;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  long long int num, x = 7, i = 1, flag = 0;
  cin >> num;

  if (num == 1 || num == 7) {
    cout << 1 << endl;
    return 0;
  }
  if (num % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (i = 1; i <= num; i++) {
    if (x % num == 0) {
      cout << i << endl;
      flag = 1;
      break;
    }
    x = (x * 10 + 7) % num;
  }
  if (flag == 0) {
    cout << -1 << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main() {

  long long int num, count = 0, x = 7;
  cin >> num;

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

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

int main() {
  int k;
  cin >> k;
  set<int> s;
  int a = 7 % k;
  int n = 1;
  while (s.count(a) == 0) {
    if (a % k == 0) {
      cout << n << endl;
      return 0;
    }
    s.insert(a);
    a = (a * 10 + 7) % k;
    n++;
  }
  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int k;
  cin >> k;
  vector<int> s;
  int a = 7;
  s.emplace_back(a);
  int n = 1;
  while (a % k != 0) {
    a = a * 10 + 7;
    a %= k;
    if (find(s.begin(), s.end(), a) == s.end()) {
      s.emplace_back(a);
      n++;
    } else {
      n = -1;
      break;
    }
  }
  cout << n << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define mem0(x) memset(x, 0, sizeof(x))
#define meminf(x) memset(x, 0x3f, sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  int k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << '\\n';
  } else {
    ll num = 7;
    ll cnt = 1;
    while (1) {
      if (num % k != 0) {
        num = (num * 10 + 7) % k;
        ++cnt;
      } else {
        break;
      }
    }
    cout << cnt << '\\n';
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define mem0(x) memset(x, 0, sizeof(x))
#define meminf(x) memset(x, 0x3f, sizeof(x))
#define VI vector<int>
#define VL vector<ll>
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << '\\n';
  } else {
    ll num = 7;
    ll cnt = 1;
    while (1) {
      if (num % k != 0) {
        num = (num * 10 + 7) % k;
        ++cnt;
      } else {
        break;
      }
    }
    cout << cnt << '\\n';
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <stack>
#include <unordered_map>

int main() {
  std ::ios_base ::sync_with_stdio(false);

  int64_t n;
  std ::cin >> n;
  int64_t ans = -1;
  int64_t seven = 7;

  for (int i = 1; i <= n; i++) {
    if (seven % n == 0) {
      ans = i;
      break;
    }

    seven = ((seven * 10) + 7) % n;
  }

  std ::cout << ans << '\\n';
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <stack>
#include <unordered_map>

int main() {
  std ::ios_base ::sync_with_stdio(false);

  int64_t n;
  std ::cin >> n;
  int64_t ans = 0;
  int64_t seven = 7;

  if (n % 2 == 0) {
    std ::cout << -1 << '\\n';
    return 0;
  }

  while (seven % n != 0) {
    ans++;
    seven = ((seven * 10) + 7) % n;
  }

  std ::cout << ans + 1 << '\\n';
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <functional>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <type_traits>
#include <vector>

using namespace std;
using ll = long long;
using Vec = vector<ll>;
using P = pair<ll, ll>;
using VecP = vector<P>;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

// static const ll MOD = 1000000007;
// static const ll INF = 1000000000000000000;
// #define PI 3.14159265358979323846
//
// int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
//
// int findSumDigits(int s) {
//     int num = 0;
//     int temp = 0;
//     while (s) {
//         temp = s % 10;
//         num += temp;
//         s = s / 10;
//     }
//     return num;
// }
//
// int countDivisorNum(int n) {
//     int count = 0;
//     for (int i = 1; i <= n; i++) {
//         if (n % i == 0) {
//             count++;
//         }
//     }
//     return count;
// }

int main() {
  ll k;
  cin >> k;
  ll count = 1;

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

  ll temp = 7 % k;
  if (temp == 0) {
    cout << count << endl;
    return 0;
  }

  while (1) {
    count++;
    temp = (temp * 10 + 7) % k;
    if (temp == 0) {
      break;
    }
  }

  cout << count << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <functional>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <type_traits>
#include <vector>

using namespace std;
using ll = long long;
using Vec = vector<ll>;
using P = pair<ll, ll>;
using VecP = vector<P>;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

// static const ll MOD = 1000000007;
// static const ll INF = 1000000000000000000;
// #define PI 3.14159265358979323846
//
// int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
//
// int findSumDigits(int s) {
//     int num = 0;
//     int temp = 0;
//     while (s) {
//         temp = s % 10;
//         num += temp;
//         s = s / 10;
//     }
//     return num;
// }
//
// int countDivisorNum(int n) {
//     int count = 0;
//     for (int i = 1; i <= n; i++) {
//         if (n % i == 0) {
//             count++;
//         }
//     }
//     return count;
// }

int main() {
  ll k;
  cin >> k;
  ll ori = 7;
  ll count = 1;
  ll temp = ori % k;

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

  while (1) {
    count++;
    temp = (temp * 10 + 7) % k;
    if (temp == 0) {
      break;
    }
  }

  cout << count << endl;

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

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void YN(bool flg) {
  if (flg)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void Yn(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
void yn(bool flg) {
  if (flg)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}

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;
}

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

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

  int mod = 7 % k;
  int cnt = 1;
  set<int> s;
  while (!s.count(mod)) {
    if (mod == 0) {
      cout << cnt << endl;
      return 0;
    }
    s.insert(mod);
    mod = (mod * 10 + 7) % k;
    cnt++;
  }

  cout << -1 << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void YN(bool flg) {
  if (flg)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void Yn(bool flg) {
  if (flg)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
void yn(bool flg) {
  if (flg)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}

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;
}

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

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

  int mod = 7 % k;
  int cnt = 1;
  set<int> s;
  while (!s.count(mod)) {
    if (mod == 0) {
      cout << cnt << endl;
      return 0;
    }
    s.count(mod);
    mod = (mod * 10 + 7) % k;
    cnt++;
  }

  cout << -1 << 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 tmp = 7 % k;
  int cnt = 1;
  for (int i = 0; i < k; i++) {
    if (tmp == 0) {
      break;
    }
    tmp = (tmp * 10 + 7) % k;
    cnt++;
  }
  if (tmp != 0) {
    cnt = -1;
  }
  cout << cnt << endl;
}


Error: TLE

Fixed submission:

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

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

  if (k % 4 != 1 && k % 4 != 3) {
    cout << -1 << endl;
  } else {
    int tmp = 7 % k;
    int cnt = 1;
    while (tmp != 0) {
      tmp = (tmp * 10 + 7) % k;
      cnt++;
    }
    cout << cnt << endl;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, m, t, a[100005];
vector<ll> adj[100005];
#define ari                                                                    \\
  for (int i = 0; i < n; i++)                                                  \\
    cin >> a[i];
#define ginp                                                                   \\
  for (int i = 0; i < m; i++) {                                                \\
    int u, v;                                                                  \\
    cin >> u >> v;                                                             \\
    adj[u].push_back(v);                                                       \\
    adj[v].push_back(u);                                                       \\
  }
#define pb push_back
#define ss second
#define ff first
#define fs first.second
#define fff first.first
#define sss second.second
#define sf second.first
#define mp make_pair

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll k;
  cin >> k;
  if (k % 2 == 0 or k % 5 == 0) {
    cout << "-1" << endl;
    return (0);
  }
  ll po = (7 % k), prev = 0, ans = 0;
  for (int i = 1;; i++) {
    if ((po + prev) % k == 0) {
      ans = i;
      break;
    }
    prev = (po + prev) % k;
    po = (po * 10) % k;
  }
  cout << ans << endl;
  return (0);
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
ll n, m, t, a[100005];
vector<ll> adj[100005];
#define ari                                                                    \\
  for (int i = 0; i < n; i++)                                                  \\
    cin >> a[i];
#define ginp                                                                   \\
  for (int i = 0; i < m; i++) {                                                \\
    int u, v;                                                                  \\
    cin >> u >> v;                                                             \\
    adj[u].push_back(v);                                                       \\
    adj[v].push_back(u);                                                       \\
  }
#define pb push_back
#define ss second
#define ff first
#define fs first.second
#define fff first.first
#define sss second.second
#define sf second.first
#define mp make_pair

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << "-1" << endl;
    return (0);
  }
  ll po = (7 % k), prev = 0, ans = 0;
  for (int i = 1;; i++) {
    if ((po + prev) % k == 0) {
      ans = i;
      break;
    }
    prev = (po + prev) % k;
    po = (po * 10) % k;
  }
  cout << ans << endl;
  return (0);
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int K;
  cin >> K;
  long long int N = 0;
  if (K % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  int ans = 1;
  while (N >= 0) {
    N = (N * 10 + 7) % K;
    if (ans > K) {
      cout << "-1" << endl;
      break;
    }
    if (N == 0) {
      cout << ans << endl;
      break;
    }
    ans++;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int K;
  cin >> K;
  long long int N = 7;
  if (K % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  int ans = 0;
  while (N > 0) {
    ans++;
    if (N % K == 0) {
      cout << ans << endl;
      break;
    } else {
      N *= 10;
      N += 7;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main(void) {
  int n, i, k, now = 7, ans = 1;

  cin >> n;

  if (n % 2 == 0 || n % 5 == 0) {
    cout << -1 << "\\n";
  } else {
    while (1) {
      if (now % n == 0) {
        cout << ans << "\\n";

        break;
      } else {
        ans++;

        now = (now * 10 + 7) % n;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define int long long

using namespace std;

signed main(void) {
  int n, i, k, now = 7, ans = 1;

  cin >> n;

  if (n % 2 == 0 || n % 5 == 0) {
    cout << -1 << "\\n";
  } else {
    while (1) {
      if (now % n == 0) {
        cout << ans << "\\n";

        break;
      } else {
        ans++;

        n = n % 1000000;

        now = now * 10 + 7;

        now = now % 1000000;
      }
    }
  }

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

#include <iostream>

using namespace std;

int main(void) {
  long long k;

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

  long long next_inc = 70;
  long long ex = 7;
  int cnt = 1;
  while (ex % k != 0) {
    ex %= k;
    ex += next_inc;

    next_inc *= 10;
    next_inc %= k;
    cnt += 1;
  }

  cout << cnt << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main(void) {
  long long k;

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

  long long next_inc = 70;
  long long ex = 7;
  int cnt = 1;
  while (ex % k != 0) {
    ex %= k;
    ex += next_inc;

    next_inc *= 10;
    next_inc %= k;
    cnt += 1;
  }

  cout << cnt << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int k, val = 7, i = 1;
  cin >> k;
  unordered_set<int> st;
  while (1) {
    val = val % k;
    if (st.find(val) != st.end()) {
      cout << -1 << '\\n';
      return 0;
    }
    st.insert(val);
    if (val == 0) {
      break;
    }
    val = val * 10 + 7;
    i++;
  }
  cout << i << '\\n';
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int k, val = 7, i = 1;
  cin >> k;

  while (1) {
    val = val % k;
    if (val == 0) {
      break;
    }
    val = val * 10 + 7;
    i++;
  }
  cout << i << '\\n';
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define endl "\\n"
using namespace std;

const int mod = 1e9 + 7;
int32_t main() {

  fast int x;
  cin >> x;

  if (x % 2 == 0)
    cout << -1 << endl;
  else {
    int ans = 1;
    int n = 7;
    while (n % x != 0 && ans < 2000000) {
      n = n * 10;
      n += 7;
      n %= x;
      ans++;
    }
    if (ans == 2000000)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define int long long
#define endl "\\n"
using namespace std;

const int mod = 1e9 + 7;
int32_t main() {

  fast int x;
  cin >> x;

  if (x % 2 == 0)
    cout << -1 << endl;
  else {
    int ans = 1;
    int n = 7;
    while (n % x != 0) {
      n = n * 10;
      n += 7;
      n %= x;
      ans++;
    }
    cout << ans << endl;
  }

  return 0;
}