prithivMLmods/Coder-Stat huggingface dataset:
Problem p02596 (C++)

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

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

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

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

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

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

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

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000

using namespace std;

void solve() {
  ll k;
  cin >> k;
  if (k % 2 == 0)
    cout << -1 << endl;
  else {
    ll ans = 1;
    ll x = 7;
    while (x % k != 0) {
      x *= 10;
      x += 7;
      x %= k;
      ans++;
    }
    cout << ans << endl;
  }
}

int32_t main() {
  IOS ll T = 1;
  // 	cin >> T;
  for (ll i = 1; i <= T; ++i) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000

using namespace std;

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

int32_t main() {
  IOS ll T = 1;
  // 	cin >> T;
  for (ll i = 1; i <= T; ++i) {
    // cout<<"Case #"<<i<<": ";
    solve();
  }
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

int main() {
  long long ch, i = 1, n, q, k, l, r;
  long long j;
  cin >> n;
  ch = 7;
  if (n % 2 != 0) {
    while (ch % n != 0) {
      i++;
      ch = (ch * 10 + 7) % n;
    }
    cout << i;
  } else
    cout << -1;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;

int main() {
  long long ch, i = 1, n, q, k, l, r;
  long long j;
  cin >> n;
  ch = 7;
  if (n % 2 != 0) {
    while (ch % n != 0) {
      i++;
      ch = (ch * 10 + 7) % n;
      if (i > n) {
        cout << -1;
        return 0;
      }
    }
    cout << i;
  } else
    cout << -1;

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

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

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

  int index = 1;
  ll base = 7;
  while (true) {
    if (base % k == 0)
      break;
    base %= k;
    index++;
    base = base * 10 + 7;
  }

  cout << index << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

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

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

  int index = 1;
  ll base = 7;
  while (true) {
    if (base % k == 0)
      break;
    base %= k;
    index++;
    base = base * 10 + 7;
    if (index > 10000000) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << index << endl;
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define f0(i, a, n) for (i = a; i < n; i++)
#define f1(i, a, n) for (i = a; i <= n; i++)
#define tc(t)                                                                  \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define ini(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define ll long long int
#define vi vector<int>
#define si set<int>
#define pb push_back
#define mp make_pair
#define M 1e9 + 7
#define rr return 0
#define endl '\n'

using namespace std;

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

int main() {
  IOS;
  solve();
  rr;
}

Fixed submission:
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define f0(i, a, n) for (i = a; i < n; i++)
#define f1(i, a, n) for (i = a; i <= n; i++)
#define tc(t)                                                                  \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define ini(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define ll long long int
#define vi vector<int>
#define si set<int>
#define pb push_back
#define mp make_pair
#define M 1e9 + 7
#define rr return 0
#define endl '\n'

using namespace std;

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

int main() {
  IOS;
  solve();
  rr;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define Rep(i, a, b) for (int i = a; i <= b; i++)
#define _Rep(i, a, b) for (int i = a; i >= b; i--)
#define RepG(i, u) for (int i = head[u]; ~i; i = e[i].next)

typedef long long ll;

const int N = 1e5 + 5;

template <typename T> void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 1) + (x << 3) + c - '0';
  x *= f;
}

int n;

int main() {
  read(n);
  if (n % 2 == 0)
    return puts("-1"), 0;
  int k = 0, ans = 0;
  while (1) {
    k = k * 10 + 7, k %= n;
    ans++;
    if (!k)
      break;
  }
  printf("%d\n", ans);
  return 0;
}

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

#define Rep(i, a, b) for (int i = a; i <= b; i++)
#define _Rep(i, a, b) for (int i = a; i >= b; i--)
#define RepG(i, u) for (int i = head[u]; ~i; i = e[i].next)

typedef long long ll;

const int N = 1e5 + 5;

template <typename T> void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = (x << 1) + (x << 3) + c - '0';
  x *= f;
}

int n;

int main() {
  read(n);
  if (n % 2 == 0)
    return puts("-1"), 0;
  int k = 0, ans = 0;
  while (1) {
    k = k * 10 + 7, k %= n;
    ans++;
    if (!k)
      break;
    if (ans > 5e7)
      return puts("-1"), 0;
  }
  printf("%d\n", ans);
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

void header() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

void solve() {
  ll res = 1, num = 7;
  int k;
  cin >> k;
  if (k & 1) {
    while (1) {
      if (num % k == 0)
        break;
      num = num * 10 + 7;
      num %= k;
      res++;
    }
  } else
    res = -1;
  cout << res << endl;
}

int main() {
  header();
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

void header() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

void solve() {
  ll res = 1, num = 7;
  int k;
  cin >> k;
  if (k & 1) {
    while (1) {
      if (res >= 1e7) {
        res = -1;
        break;
      }
      if (num % k == 0)
        break;
      num = num * 10 + 7;
      num %= k;
      res++;
    }
  } else
    res = -1;
  cout << res << endl;
}

int main() {
  header();
  solve();
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int k;
  cin >> k;
  long long t = 7;
  int count = 1;
  if (k % 2 == 0) {
    cout << -1;
    return 0;
  }
  while (true) {
    if (t % k == 0)
      break;
    else {
      t = ((t * 10) % k + 7) % k;
      count++;
    }
  }
  cout << count;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int k;
  cin >> k;
  long long t = 7;
  int count = 1;
  if (k % 2 == 0) {
    cout << -1;
    return 0;
  }
  while (true) {
    if (t % k == 0)
      break;
    else {
      t = ((t * 10) % k + 7) % k;
      count++;
      if (count > k) {
        cout << -1;
        return 0;
      }
    }
  }
  cout << count;
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define F first
#define S second
using namespace std;

int main() {
  ll t, i, j, k, ans, n;

  // cin>>t;
  t = 1;
  while (t--) {
    ll term = 7, pos = 1;
    cin >> k;
    i = 0;

    while (i <= k * k && term % k) {
      term = (term * 10 % k + 7 % k) % k;
      pos++;
      i++;
    }

    if (term % k == 0)
      cout << pos;
    else
      cout << "-1";
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define F first
#define S second
using namespace std;

int main() {
  ll t, i, j, k, ans, n;

  // cin>>t;
  t = 1;
  while (t--) {
    ll term = 7, pos = 1;
    cin >> k;
    i = 0;

    while (i <= 2 * k && term % k) {
      term = (term * 10 % k + 7 % k) % k;
      pos++;
      i++;
    }

    if (term % k == 0)
      cout << pos;
    else
      cout << "-1";
  }

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
// sort(V.begin(), V.end(), compare_function);

/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/

/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}

void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  if (k % 7 == 0) {
    k = k / 7;
  }
  if (k % 2 == 0) {
    cout << -1 << endl;
  } else {
    int a = 1 % k;
    int l = 1;
    while (a > 0) {
      a = (10 * a + 1) % k;
      l++;
    }
    cout << l << endl;
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
// sort(V.begin(), V.end(), compare_function);

/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/

/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}

void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  if (k % 7 == 0) {
    k = k / 7;
  }
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
  } else {
    int a = 1 % k;
    int l = 1;
    while (a > 0) {
      a = (10 * a + 1) % k;
      l++;
    }
    cout << l << endl;
  }
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int64_t unit = log10(K) + 1;
  int sevens = stoi(string(unit, '7'));
  while (true) {
    sevens %= K;
    if (sevens % K == 0) {
      break;
    }
    sevens = sevens * 10 + 7;
    ++unit;
  }
  cout << unit << endl;

  return 0;
}


Fixed submission:
#include <cmath>
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int64_t unit = log10(K) + 1;
  int sevens = stoi(string(unit, '7'));
  while (true) {
    sevens %= K;
    if (sevens % K == 0) {
      break;
    }
    sevens = sevens * 10 + 7;
    ++unit;

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

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"

using namespace std;

#define all(v) v.begin(), v.end()
#define pb push_back
#define sz(x) (int)(x.size())
#define endl "\n"
#define isOdd(n) (n & 1)
#define pow(n, m) (ll) powl(n, m)
#define clr(x, val) memset(x, val, sizeof(x))
#define EPS 1e-7

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

  ll k, c = 1, x = 7;
  cin >> k;
  if (!isOdd(k))
    return cout << -1, 0;
  while (x % k != 0 && c < (int)1e8) {
    x = ((x * 10 % k) + 7) % k;
    c++;
  }
  if (x % k != 0)
    c = -1;
  cout << c;
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;

#define all(v) v.begin(), v.end()
#define pb push_back
#define sz(x) (int)(x.size())
#define endl "\n"
#define isOdd(n) (n & 1)
#define pow(n, m) (ll) powl(n, m)
#define clr(x, val) memset(x, val, sizeof(x))
#define EPS 1e-7

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

  ll k, c = 1, x = 7;
  cin >> k;
  if (!isOdd(k))
    return cout << -1, 0;
  while (x % k != 0 && c < (int)1e7) {
    x = ((x * 10 % k) + 7) % k;
    c++;
  }
  if (x % k != 0)
    c = -1;
  cout << c;
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define mx 100005
#define ll long long

int ar[mx];
char ch[mx];

int m, n, k, ii;

void solve() {
  cin >> n;
  if (n % 2 == 0) {
    cout << -1 << endl;
    return;
  }
  int cnt = 0;
  ll hate = 0;
  while (1) {
    cnt++;
    hate *= 10;
    hate += 7;
    hate %= n;
    if (hate == 0)
      break;
  }
  cout << cnt << endl;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif

  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

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

#define mx 100005
#define ll long long

int ar[mx];
char ch[mx];

int m, n, k, ii;

void solve() {
  cin >> n;
  if (n % 2 == 0) {
    cout << -1 << endl;
    return;
  }
  int cnt = 0;
  ll hate = 0;
  while (1) {
    cnt++;
    hate *= 10;
    hate += 7;
    hate %= n;
    if (hate == 0)
      break;
    if (cnt > 1000000) {
      cout << -1 << endl;
      return;
    }
  }
  cout << cnt << endl;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif

  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    printf("-1");
    return 0;
  }
  int remind = 7 % k, number = 1;
  while (remind) {
    ++number;
    remind = (remind * 10 + 7) % k;
  }
  printf("%d\n", number);
  return 0;
}

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

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    printf("-1");
    return 0;
  }
  int remind = 7 % k, number = 1;
  while (remind) {
    ++number;
    remind = (remind * 10 + 7) % k;
    if (number > 1000000) {
      cout << "-1" << endl;
      return 0;
    }
  }
  printf("%d\n", number);
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
  int K;
  cin >> K;
  int res = 1;
  int S = 7;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (S % K != 0) {
    S = S * 10 + 7;
    res++;
    S %= K;
  }
  cout << res << endl;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main() {
  int K;
  cin >> K;
  int res = 1;
  int S = 7;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (S % K != 0) {
    S = S * 10 + 7;
    res++;
    S %= K;
    if (res > K + 10) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << res << endl;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, res, count = 1;
  cin >> n;
  if (n % 2 == 0 || n % 5 == 0)
    count = -1;
  else {
    string s = "7";
    stringstream(s) >> res;
    while (res % n != 0) {
      s += "7";
      stringstream(s) >> res;
      count++;
    }
  }
  cout << count << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, res, count = 1;
  cin >> n;
  if (n % 2 == 0 || n % 5 == 0)
    count = -1;
  else {
    long long m = 7 % n;
    while (m != 0) {
      m = (m * 10 + 7) % n;
      count++;
    }
  }
  cout << count << "\n";
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1;
    return 0;
  }
  if (k % 7 == 0)
    k /= 7;
  int p = 1;
  int m = 0;
  int cnt = 0;
  do {
    m += p;
    m %= k;
    p *= 10;
    p %= k;
    ++cnt;
  } while (m);
  cout << cnt;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  int k;
  cin >> k;
  if (k % 2 == 0 or k % 5 == 0) {
    cout << -1;
    return 0;
  }
  if (k % 7 == 0)
    k /= 7;
  int p = 1;
  int m = 0;
  int cnt = 0;
  do {
    m += p;
    m %= k;
    p *= 10;
    p %= k;
    ++cnt;
  } while (m);
  cout << cnt;

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

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

  bool flag = true;
  ll rem = 7;
  ll ans = 1;
  while (flag) {
    rem = rem % k;
    if (rem == 0) {
      flag = false;
    } else {
      rem = rem * 10 + 7;
      ans++;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

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

  bool flag = true;
  ll rem = 7;
  ll ans = 1;
  while (flag) {
    rem = rem % k;
    if (rem == 0) {
      flag = false;
    } else {
      rem = rem * 10 + 7;
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int k;
  cin >> k;
  int n = 7 % k;
  if (!(k % 2))
    cout << "-1" << endl;
  else {
    for (int cnt = 1;;) {
      if (!n) {
        cout << cnt << endl;
        break;
      }
      n = (n * 10 + 7) % k;
      cnt++;
    }
  }
  return 0;
}

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

int main() {
  int k;
  cin >> k;
  int n = 7 % k;
  if (!(k % 2) || !(k % 5))
    cout << "-1" << endl;
  else {
    for (int cnt = 1;;) {
      if (!n) {
        cout << cnt << endl;
        break;
      }
      n = (n * 10 + 7) % k;
      cnt++;
    }
  }
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll k, num = 0, cnt = 0;
int main() {
  while (cnt <= k) {
    num = (num * 10 + 7) % k;
    cnt++;
    if (!num) {
      cout << cnt;
      return 0;
    }
  }
  cout << "-1";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll k, num = 0, cnt = 0;
int main() {
  cin >> k;
  while (cnt <= k) {
    num = (num * 10 + 7) % k;
    cnt++;
    if (!num) {
      cout << cnt;
      return 0;
    }
  }
  cout << "-1";
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
  int k, i, ans = -1, tmp = 0;
  for (i = 1; i <= k + 100; i++) {
    tmp = tmp * 10 + 7;
    tmp %= k;
    if (!tmp) {
      ans = i;
      break;
    }
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
  int k, i, ans = -1, tmp = 0;
  cin >> k;
  for (i = 1; i <= k + 100; i++) {
    tmp = tmp * 10 + 7;
    tmp %= k;
    if (!tmp) {
      ans = i;
      break;
    }
  }
  cout << ans;
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main(void) {
  long long K;
  cin >> K;

  if (K % 2 == 0)
    cout << -1 << endl;
  else {
    long long ans = 1;
    long long mod = 7 % K;

    while (mod != 0) {
      ans++;
      mod = (mod * 10 + 7) % K;
    }

    cout << ans << endl;
  }

  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main(void) {
  long long K;
  cin >> K;

  if (K % 2 == 0)
    cout << -1 << endl;
  else {
    long long ans = 1;
    long long mod = 7 % K;

    while (mod != 0) {
      ans++;
      mod = (mod * 10 + 7) % K;
      if (ans > 1000000) {
        cout << -1 << endl;
        return 0;
      }
    }

    cout << ans << endl;
  }

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

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

  long long i = 0;
  long long val = 0;
  long long first = -1;

  while (true) {
    i++;
    val = val * 10 + 7;
    long long rem = val % k;
    if (rem == 0) {
      break;
    }
    if (first == rem) {
      i = -1;
      break;
    }
    if (first < 0) {
      first = rem;
    }
    val = rem;
  }
  cout << i << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

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

  long long i = 0;
  long long val = 0;
  long long first = -1;

  while (true) {
    i++;
    val = val * 10 + 7;
    long long rem = val % k;
    if (rem == 0) {
      break;
    }
    if (first == rem) {
      i = -1;
      break;
    }
    if (i > 2 * k) {
      i = -1;
      break;
    }
    val = rem;
  }
  cout << i << endl;

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
#define L long
#define endl "\n"
#define ___                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
using namespace std;

const int N = (int)1e5;

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ___

      ll int n = 0,
             k, x = 0;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1;
    return 0;
  }
  while (1) {
    n = ((n * 10) + 7) % k;
    x++;
    if (n == 0)
      break;
    else if (x == (int)2e8) {
      cout << -1;
      return 0;
    }
  }
  cout << x;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define L long
#define endl "\n"
#define ___                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
using namespace std;

const int N = (int)1e5;

int main() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ___

      ll int n = 0,
             k, x = 0;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1;
    return 0;
  }
  while (1) {
    n = ((n * 10) + 7) % k;
    x++;
    if (n == 0)
      break;
    else if (x == (int)1e8 + (int)1e7) {
      cout << -1;
      return 0;
    }
  }
  cout << x;

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
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;
}
ll k;
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % (k * 9);
    }
    x = x * x % (k * 9);
    n >>= 1;
  }
  return res;
}
int main() {
  cin >> k;
  for (int i = 1; i <= 9 * k; i++) {
    // cout << i << endl;
    if (7 * ((mod_pow(10, i) - 1)) % (9 * k) == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
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;
}
ll k;
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) {
      res = res * x % (k * 9);
    }
    x = x * x % (k * 9);
    n >>= 1;
  }
  return res;
}
int main() {
  cin >> k;
  for (int i = 1; i <= k; i++) {
    // cout << i << endl;
    if (7 * ((mod_pow(10, i) - 1)) % (9 * k) == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define pb push_back
#define fori(j, n) for (int i = j; i < n; i++)
#define forj(i, n) for (int j = i; j < n; j++)
#define fork(i, n) for (int k = i; k < n; k++)
#define ppb pop_back()
#define umap unordered_map
#define uset unordered_set
#define lli long long int

using namespace std;

void solve() {
  lli k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1;
    return;
  }
  lli ans = 0;
  int cnt = 0;
  while (1) {
    cnt++;
    ans = (ans * 10 + 7) % k;
    if (ans == 0)
      break;
  }
  cout << cnt;
}

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

  // int t;cin>>t;
  // while(t--)
  // {
  solve();
  // cout<<endl;
  // }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define fori(j, n) for (int i = j; i < n; i++)
#define forj(i, n) for (int j = i; j < n; j++)
#define fork(i, n) for (int k = i; k < n; k++)
#define ppb pop_back()
#define umap unordered_map
#define uset unordered_set
#define lli long long int

using namespace std;

void solve() {
  lli k;
  cin >> k;
  if (k % 2 == 0 or k % 5 == 0) {
    cout << -1;
    return;
  }
  lli ans = 0;
  int cnt = 0;
  while (1) {
    cnt++;
    ans = (ans * 10 + 7) % k;
    if (ans == 0)
      break;
  }
  cout << cnt;
}

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

  // int t;cin>>t;
  // while(t--)
  // {
  solve();
  // cout<<endl;
  // }

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
using namespace std;

#define IOS                                                                    \
  {                                                                            \
    ios::sync_with_stdio(false);                                               \
    cin.tie(0);                                                                \
    cout.tie(0);                                                               \
  }
#define ll long long
ll powermod(ll x, ll ex, ll md) {
  ll ans = 1ll;
  while (ex > 0) {
    if (ex & 1ll)
      ans = (ans * x) % md;
    ex >>= 1ll;
    x = (x * x) % md;
  }
  return ans;
}

int main() {
  IOS;
  ll n;
  cin >> n;
  // vector<ll> factor;

  // for(ll i=1;i*i<=n;++i){
  //     if(n%i==0){
  //         ll div1=i,div2=n/i;
  //         factor.push_back(div1);
  //         if(div1 != div2) factor.push_back(div2);
  //     }
  // }

  // for(ll i=0;i<(int)(factor.size());i++) cout << factor[i] <<" ";

  ll ans = -1;
  if (n == 7) {
    cout << 1 << "\n";
    return 0;
  } else if (n % 2 == 0) {
    cout << -1 << "\n";
    return 0;
  }

  n *= 9;
  for (ll i = 1; i <= 1e7; i++) {
    ll b = 3;
    ll a = powermod(10, i, n);
    a %= n;
    (a) = (a - 1 + n) % n;

    a = ((a % n) * 7) % n;
    if (a == 0) {
      ans = i;
      break;
    }
  }
  if (ans != -1)
    cout << ans << "\n";
  else
    cout << -1 << "\n";
}


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

#define IOS                                                                    \
  {                                                                            \
    ios::sync_with_stdio(false);                                               \
    cin.tie(0);                                                                \
    cout.tie(0);                                                               \
  }
#define ll long long
ll powermod(ll x, ll ex, ll md) {
  ll ans = 1ll;
  while (ex > 0) {
    if (ex & 1ll)
      ans = (ans * x) % md;
    ex >>= 1ll;
    x = (x * x) % md;
  }
  return ans;
}

int main() {
  IOS;
  ll n;
  cin >> n;
  // vector<ll> factor;

  // for(ll i=1;i*i<=n;++i){
  //     if(n%i==0){
  //         ll div1=i,div2=n/i;
  //         factor.push_back(div1);
  //         if(div1 != div2) factor.push_back(div2);
  //     }
  // }

  // for(ll i=0;i<(int)(factor.size());i++) cout << factor[i] <<" ";

  ll ans = -1;
  if (n == 7) {
    cout << 1 << "\n";
    return 0;
  } else if (n % 2 == 0) {
    cout << -1 << "\n";
    return 0;
  }

  n *= 9;
  for (ll i = 1; i <= 1e6; i++) {
    ll b = 3;
    ll a = powermod(10, i, n);
    a %= n;
    (a) = (a - 1 + n) % n;

    a = ((a % n) * 7) % n;
    if (a == 0) {
      ans = i;
      break;
    }
  }
  if (ans != -1)
    cout << ans << "\n";
  else
    cout << -1 << "\n";
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int K;
  // 入力
  cin >> K;
  int ans = -1;
  int o;
  o = K / 10;
  if (K % 2 != 0 and K % 5 != 0) {
    for (int i = o; i >= 0; i++) {
      int seven = 0;
      for (int j = 0; j <= i; j++) {
        seven = seven + 7 * pow(10, j);
      }
      if (seven % K == 0) {
        ans = i + 1;
        break;
      }
    }
  }
  cout << ans << endl;
}


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

int main() {
  int K;
  // 入力
  cin >> K;
  int ans = -1;
  int seven = 0;
  for (int i = 1; i <= 1000001; i++) {
    seven = 10 * seven % K + 7;
    if (seven % K == 0) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}
Problem p02596 (C++)

Buggy submission (status: Runtime Error):
/*
Author:loceaner
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define int long long
using namespace std;

const int A = 1e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + (c ^ 48);
  return x * f;
}

int k, a[A];

signed main() {
  k = read();
  for (int i = 1; i <= k; i++) {
    a[i] = a[i - 1] * 10 + 7;
    a[i] %= k;
    if (a[i] == 0) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
}

Fixed submission:
/*
Author:loceaner
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define int long long
using namespace std;

const int A = 1e6 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + (c ^ 48);
  return x * f;
}

int k, a[A];

signed main() {
  k = read();
  for (int i = 1; i <= k; i++) {
    a[i] = a[i - 1] * 10 + 7;
    a[i] %= k;
    if (a[i] == 0) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
}
Problem p02596 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
  int k;
  cin >> k;
  bool flag = false;

  ll l = (k % 7 == 0) ? 9 * k / l : 9 * k;
  ll n = 1;
  for (ll i = 1; i <= l; i++) {
    n = (n % l) * 10 % l;
    if (n == 1) {
      cout << i << endl;
      flag = true;
      break;
    }
  }

  if (!flag)
    cout << -1 << endl;

  return 0;
}


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

int main() {
  int k;
  cin >> k;
  bool flag = false;

  ll l = (k % 7 == 0) ? 9 * k / 7 : 9 * k;
  ll n = 1;
  for (ll i = 1; i <= l; i++) {
    n = (n % l) * 10 % l;
    if (n == 1) {
      cout << i << endl;
      flag = true;
      break;
    }
  }

  if (!flag)
    cout << -1 << endl;

  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  ll k;
  vector<int> v = vector<int>(k, -1);
  v[0] = 0;
  ll a = 0;
  ll idx = 1;
  while (true) {
    a = a * 10 + 7;
    a %= k;
    if (v[a] != -1) {
      cout << idx - v[a] << endl;
      return 0;
    } else {
      v[a] = idx;
    }
    idx++;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  ll k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> v = vector<int>(k, -1);
  v[0] = 0;
  ll a = 0;
  ll idx = 1;
  while (true) {
    a = a * 10 + 7;
    a %= k;
    if (v[a] != -1) {
      cout << idx - v[a] << endl;
      return 0;
    } else {
      v[a] = idx;
    }
    idx++;
  }
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

ll x;

bool chk(int x) {
  if (x == 0)
    return 0;
  while (x) {
    if (x % 10 != 1)
      return 0;
    x /= 10;
  }
  return 1;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> x;
  int cnt = 0;
  ll tmp = 0;
  if (x % 7 == 0)
    x /= 7;
  while (1) {
    int y = ((11 - tmp % 10) % 10);

    if (chk(tmp)) {
      while (tmp)
        tmp /= 10, cnt++;
      cout << cnt;
      return 0;
    }

    bool pos = 0;
    for (int i = 0; i < 10; i++)
      if (i * x % 10 == y) {
        tmp += x * i;
        tmp /= 10;
        pos = 1;
        break;
      }
    if (pos)
      cnt++;
    else {
      cout << -1;
      return 0;
    }
  }
}


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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;

ll x;

bool chk(int x) {
  if (x == 0)
    return 0;
  while (x) {
    if (x % 10 != 1)
      return 0;
    x /= 10;
  }
  return 1;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> x;
  int cnt = 0;
  ll tmp = 0;
  if (x % 7 == 0)
    x /= 7;
  if (x == 1) {
    cout << 1;
    return 0;
  }
  while (1) {
    int y = ((11 - tmp % 10) % 10);

    if (chk(tmp)) {
      while (tmp)
        tmp /= 10, cnt++;
      cout << cnt;
      return 0;
    }

    bool pos = 0;
    for (int i = 0; i < 10; i++)
      if (i * x % 10 == y) {
        tmp += x * i;
        tmp /= 10;
        pos = 1;
        break;
      }
    if (pos)
      cnt++;
    else {
      cout << -1;
      return 0;
    }
  }
}
Problem p02596 (C++)

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

int main() {
  ll n;
  cin >> n;
  ll tmp = 7;
  //    ll ans = 0;

  for (ll i = 1; i < 1000000000; ++i) {
    if (tmp % n == 0) {
      cout << i << endl;
      return 0;
    }
    tmp *= 10;
    tmp += 7;
    tmp %= n;
  }
  cout << -1 << endl;
  //    cout<<ans<<endl;
  return 0;
}

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

int main() {
  ll n;
  cin >> n;
  ll tmp = 7;
  //    ll ans = 0;

  for (ll i = 1; i < 100000000; ++i) {
    if (tmp % n == 0) {
      cout << i << endl;
      return 0;
    }
    tmp *= 10;
    tmp += 7;
    tmp %= n;
  }
  cout << -1 << endl;
  //    cout<<ans<<endl;
  return 0;
}
Problem p02596 (C++)

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

int main() {
  ll K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = 1;
  ll x = 7;
  x %= K;
  while (x) {
    ans++;
    x = x * 10 + 7;
    x %= K;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  ll K;
  cin >> K;
  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = 1;
  ll x = 7;
  x %= K;
  while (x) {
    ans++;
    x = x * 10 + 7;
    x %= K;
  }
  cout << ans << endl;
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << "\n";
    return 0;
  }
  lint res = 7 % k;
  lint ret = 1;
  while (res != 0) {
    res = (res * 10 + 7) % k;
    ret++;
  }
  cout << ret << "\n";
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << "\n";
    return 0;
  }
  lint res = 7 % k;
  lint ret = 1;
  while (res != 0) {
    res = (res * 10 + 7) % k;
    ret++;
    if (ret > k) {
      cout << -1 << "\n";
      return 0;
    }
  }
  cout << ret << "\n";
  return 0;
}
Problem p02596 (C++)

Buggy submission (status: Time Limit Exceeded):
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i > ll(b); i--)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Umap unordered_map
#define Uset unordered_set

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

  ll K;
  cin >> K;

  ll ans = 0;
  if (K % 2 == 0 || K % 5 == 0)
    ans = -1;

  ll cnt = 1;
  ll warareru = 7;
  while (true) {
    ll amari = warareru % K;
    if (amari == 0)
      break;

    warareru = (amari * 10 + 7);
    cnt++;
  }

  cout << cnt << endl;

  return 0;
}

Fixed submission:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i > ll(b); i--)
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define Umap unordered_map
#define Uset unordered_set

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

  ll K;
  cin >> K;

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

  ll cnt = 1;
  ll warareru = 7;
  while (true) {
    ll amari = warareru % K;
    if (amari == 0)
      break;

    warareru = (amari * 10 + 7);
    cnt++;
  }

  cout << cnt << endl;

  return 0;
}
Problem p02596 (Python)

Buggy submission (status: Time Limit Exceeded):
K = int(input())
if K % 2 == 0:
    print(-1)
else:
    r = 0
    rem = 7
    while True:
        r += 1
        rem = rem % K
        if rem == 0:
            break
        rem = (rem * 10) + 7
    print(r)


Fixed submission:
K = int(input())
if K % 2 == 0:
    print(-1)
else:
    r = 0
    rem = 7
    while True:
        r += 1
        rem = rem % K
        if rem == 0:
            break
        if r > K:
            r = -1
            break
        rem = (rem * 10) + 7
    print(r)
Problem p02596 (Python)

Buggy submission (status: Time Limit Exceeded):
K = int(input())
count = 1
check = 7

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    while True:
        if check % K == 0:
            print(count)
            break
        else:
            count += 1
            check = check * 10 + 7


Fixed submission:
K = int(input())
count = 1
check = 7

if K % 2 == 0 or K % 5 == 0:
    print(-1)
else:
    while True:
        if check % K == 0:
            print(count)
            break
        else:
            count += 1
            check = (check * 10 + 7) % K