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

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
// 　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1000000007;
const ll mod = 1000000007;
const double PI = 3.14159265358979323846;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

int cans(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

int main() {
  ll ans = 1;
  ll K;
  cin >> K;
  vector<bool> seen(K, false);
  ll mod = 7 % K;
  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    if (mod == 0) {
      cout << ans << endl;
      return 0;
    } else {
      seen[mod] = true;
      mod = mod * 10 + 7;
      mod %= K;
      ans++;
    }
    // cout << mod << endl;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
// 　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1000000007;
const ll mod = 1000000007;
const double PI = 3.14159265358979323846;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

ll gcd(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}

int cans(bool f) {
  if (f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

int main() {
  ll ans = 1;
  ll K;
  cin >> K;
  vector<bool> seen(K, false);
  ll mod = 7 % K;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    if (mod == 0) {
      cout << ans << endl;
      return 0;
    } else {
      seen[mod] = true;
      mod = mod * 10 + 7;
      mod %= K;
      ans++;
    }
    // cout << mod << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
bool checkValue(long long v) {
  while (v > 0) {
    if ((v % 7 != 0) || (v % 10 == 0))
      return false;
    v /= 10;
  }
  return true;
}
int main() {
  long long x;
  cin >> x;
  unsigned long long value = 7;
  vector<long long> result;
  long long cnt = 0;
  while (value > 0) {
    cnt++;
    // cout << value%x << endl;
    value = value % x;
    if (value == 0) {
      cout << cnt << endl;
      return 0;
    }
    // if(result.size()%10000!=0){
    // for(long long i = 0; i < result.size(); i++){
    // if(result[i]==value){
    // cout << -1 << endl;
    // return 0;
    //}
    //}
    //}
    if (result.size() >= 10000000) {
      cout << -1 << endl;
      return 0;
    }
    result.push_back(value);
    value = value * 10 + 7;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
bool checkValue(long long v) {
  while (v > 0) {
    if ((v % 7 != 0) || (v % 10 == 0))
      return false;
    v /= 10;
  }
  return true;
}
int main() {
  long long x;
  cin >> x;
  unsigned long long value = 7;
  vector<long long> result;
  long long cnt = 0;
  while (value > 0) {
    cnt++;
    // cout << value%x << endl;
    value = value % x;
    if (value == 0) {
      cout << cnt << endl;
      return 0;
    }
    if (result.size() != 0) {
      for (long long i = 0; i < result.size(); i++) {
        if (result[i] == value) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
    result.push_back(value);
    value = value * 10 + 7;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int, long long int>, null_type,
             less<pair<long long int, long long int>>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

void go() {
  int k, x = 1e6;
  cin >> k;
  int st = 7, ans = 0;
  map<int, int> h;
  for (int i = 0; i <= x; i++) {
    h[st]++;
    if (st % k == 0 || st == 0) {
      cout << ans + 1;
      return;
    }
    st = st * 10 + 7;
    st = st % k;
    ans++;
    if (h[st] != 0) {
      cout << -1;
      return;
    }
  }
}
int main() {
  FIO;
  //    int t;
  //    cin>>t;
  //    while(t--)
  go();
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#define FIO                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define ll long long
using namespace std;
using namespace __gnu_pbds;

typedef tree<pair<long long int, long long int>, null_type,
             less<pair<long long int, long long int>>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

void go() {
  ll int k, x = 1e7;
  cin >> k;
  ll int st = 7, ans = 0;
  map<ll int, ll int> h;
  for (int i = 0; i <= x; i++) {
    h[st]++;
    // cout<<st<<endl;
    if (st % k == 0 || st == 0) {
      cout << ans + 1;
      return;
    } else if (st < k)
      st = st * 10 + 7, ans++;
    else if (st > k)
      st = st % k;
    if (h[st] != 0) {
      cout << -1;
      return;
    }
  }
}
int main() {
  FIO;
  //    int t;
  //    cin>>t;
  //    while(t--)
  go();
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define scan(a, n)                                                             \\
  for (long int index = 0; index < n; index++)                                 \\
    cin >> a[index];
#define print(a, n)                                                            \\
  for (long int index = 0; index < n; index++)                                 \\
    cout << a[index] << " ";                                                   \\
  cout << endl;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define vli vector<long long int>
#define vlli vector<pair<long long int, long long int>>
#define vsi vector<string>
#define vci vector<char>

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast;
  ll k;
  cin >> k;
  ll x = 7, ans = 1;
  map<ll, ll> m;
  if (k % 2 == 0) {
    cout << -1;
    return 0;
  }
  while (x % k != 0) {
    x = x % k;
    if (m[x] == 0)
      m[x]++;
    else if (m[x] > 0) {
      cout << -1;
      return 0;
    }
    ans++;
    x = x * 10 + 7;
  }
  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
#define scan(a, n)                                                             \\
  for (long int index = 0; index < n; index++)                                 \\
    cin >> a[index];
#define print(a, n)                                                            \\
  for (long int index = 0; index < n; index++)                                 \\
    cout << a[index] << " ";                                                   \\
  cout << endl;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define vli vector<long long int>
#define vlli vector<pair<long long int, long long int>>
#define vsi vector<string>
#define vci vector<char>

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  fast;
  ll k;
  cin >> k;
  ll x = 7, ans = 1, y, z;
  if (k % 2 == 0) {
    cout << -1;
    return 0;
  }
  while (x % k != 0) {
    x = x % k;

    ans++;
    z = 7;
    y = x;
    x = x * 10 + 7;
    // cout<<x<<endl;
  }
  cout << ans << endl;

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

#include <bits/stdc++.h>

using namespace std;

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

int main() {
  int k;
  cin >> k;
  if (k % 7 == 0) {
    k = k / 7;
  }
  if (gcd(10, k) != 1) {
    cout << -1 << endl;
    return 0;
  }
  long long int l = 1, v = 1 % k;
  while (v != 0) {
    l++;
    v = (v * 10 + 1) % k;
  }
  cout << l << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

int main() {
  int k;
  cin >> k;
  if (k % 7 == 0) {
    k = k / 7;
  }
  if (gcd(10, k) != 1) {
    cout << -1 << endl;
  }
  long long int l = 1, v = 1 % k;
  while (v != 0) {
    l++;
    v = (v * 10 + 1) % k;
  }
  cout << l << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int k;
  cin >> k;
  int x = 7 % k;
  set<int> s;
  int i = 1;
  while (s.count(x) == 0) {
    if (x == 0) {
      cout << i << endl;
      return 0;
    }
    s.insert(x);
    x = (x * 10 + 7) % k;
    i++;
  }
  cout << -1 << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long K;
  cin >> K;
  if (K % 2 == 0) {
    cout << "-1";
  }
  long long sum = 0;
  long long counter = 1;
  long long j = 1;
  while (true) {
    long long i = 7;
    sum += i * j;
    long long amari = sum % K;
    if (amari == 0) {
      break;
    }
    counter++;
    j *= 10;
  }
  cout << counter << endl;
}
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;
typedef long long ll;

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

  int cnt = 0;
  bool valid = false;
  ll target = 7;
  while (true) {
    cnt++;
    if (target % k == 0) {
      valid = true;
      break;
    }
    if (cnt > 1000005) {
      break;
    }
    target = target * 10 % k;
    target = (target + 7) % k;
  }
  if (valid) {
    cout << cnt << endl;
  } else {
    cout << -1 << endl;
  }
}


Error: TLE

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

  int cnt = 0;
  ll target = 7;
  while (true) {
    cnt++;
    if (target % k == 0) {
      break;
    }
    target = target * 10 % k;
    target = (target + 7) % k;
  }
  cout << cnt << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

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

  ll p = 1;
  ll r = 0;
  int ans = 0;
  rep(i, 10010010) {
    ++ans;
    r += (7 * p) % k;
    r %= k;
    if (r == 0) {
      cout << ans << endl;
      return 0;
    }
    p = (p * 10) % k;
  }
  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

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

  ll p = 1;
  ll r = 0;
  int ans = 0;
  while (true) {
    ++ans;
    r += (7 * p) % k;
    r %= k;
    if (r == 0) {
      cout << ans << endl;
      return 0;
    }
    p = (p * 10) % k;
  }
  cout << ans << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded



#include <bits/stdc++.h>
#include <math.h>
#include <string.h>
#include <vector>
// s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rep(i, a, n) for (int i = a; i < n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i / 3][i % 3]

int main() {

  long long k, ans = 0;
  cin >> k;

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

  cout << "-1" << endl;

  return 0;
}

Error: TLE

Fixed submission:


#include <bits/stdc++.h>
#include <math.h>
#include <string.h>
#include <vector>
// s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define rep(i, a, n) for (int i = a; i < n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i / 3][i % 3]

int main() {

  long long k;
  cin >> k;

  long long ans = 7, index = 1;
  string s = "7";

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

  if (ans % k == 0)
    cout << index << endl;
  else {
    while (true) {
      s += "7";
      int fact = 1, num = 0;
      for (int i = 0; i < s.length(); i++) {
        num += (s[i] - '0') * fact;
        fact = fact * 10;
      }

      index++;

      if (num % k == 0) {
        cout << index << endl;
        // break;
        return 0;
      }
    }
  }

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

#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 1; i <= (n); i++)
#define drep(i, n) for (int i = (n)-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define rng(a) a.begin(), a.end()
using ll = long long;

using namespace std;

int main() {
  int k;
  cin >> k;
  ll n = 7 % k;
  int ans = 1;
  vector<ll> a(k);
  while (1) {
    if (n == 0) {
      cout << ans << endl;
      return 0;
    }
    if (a[n]) {
      cout << -1 << endl;
      return 0;
    }
    a[n]++;
    n = (10 * n + 7) % k;
    ans++;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = 1; i <= (n); i++)
#define drep(i, n) for (int i = (n)-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define rng(a) a.begin(), a.end()
using ll = long long;

using namespace std;

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

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

#include <bits/stdc++.h>

using namespace std;

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

  if (n % 2 == 0 || n % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  long long c = 1;
  int m = 7;
  while (m < n) {
    c++;
    m = 10 * m + 7;
  }
  //    cout << m << endl;
  while (true) {
    int mod = m % n;
    if (mod == 0)
      break;
    m = 10 * mod + 7;
    c++;
    //        cout << m << endl;
  }
  cout << c << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

  if (n % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int c = 1;
  int m = 7;
  while (m < n) {
    c++;
    m = 10 * m + 7;
  }
  //    cout << m << endl;
  while (true) {
    int mod = m % n;
    if (mod == 0)
      break;
    m = 10 * mod + 7;
    c++;
    //        cout << m << endl;
  }
  cout << c << 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<ll> vint;
typedef vector<vector<ll>> vvint;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define repf(i, f, n) for (ll i = f; i < n; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};

int main() {
  cout << fixed << setprecision(10);

  ll k;
  cin >> k;

  vector<bool> v(k, false);
  ll m = 0;
  ll ans = 1;

  while (true) {
    m = (m * 10 + 7) % k;
    if (m == 0) {
      cout << ans << endl;
      return 0;
    }
    if (v[m])
      break;
    v[m] = true;
    ans++;
  }

  cout << -1 << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define repf(i, f, n) for (ll i = f; i < n; i++)
#define repr(i, n) for (ll i = n - 1; i >= 0; i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};

int main() {
  cout << fixed << setprecision(10);

  ll k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll m = 0;
  ll x = 7;
  ll ans = 1;
  ll fac = 1;
  while (true) {
    m = (m + 7 * fac) % k;
    if (m == 0) {
      cout << ans << endl;
      return 0;
    }

    fac = (fac * 10) % k;
    ans++;
  }

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

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
int k;
int mo = 7, used[2000005], ans;
int main() {
  scanf("%d", &k);
  if (k % 2 == 0)
    puts("-1");
  else {
    mo = 7 % k;
    used[mo] = 1;
    bool flg = 0;
    while (mo != 0) {
      ++ans;
      mo *= 10;
      mo += 7;
      mo %= k;
      if (used[mo]) {
        flg = 1;
        printf("-1\\n");
        break;
      }
      used[mo] = 1;
    }
    if (!flg)
      printf("%d\\n", ans + 1);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
int k;
int mo = 7, chu, ans;
int main() {
  scanf("%d", &k);
  if (k % 2 == 0)
    puts("-1");
  else {
    mo %= k;
    chu = mo;
    bool flg = 0;
    while (mo != 0) {
      ++ans;
      mo *= 10;
      mo += 7;
      mo %= k;
      if (mo == chu) {
        flg = 1;
        printf("-1\\n");
        break;
      }
    }
    if (!flg)
      printf("%d\\n", ans + 1);
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  ll k;
  cin >> k;

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

  int ans = 1;
  ll r = 7 % k;
  while (r != 0) {
    r = r * 10 + 7;
    r %= k;
    ans++;
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  ll k;
  cin >> k;

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

  int ans = 1;
  ll r = 7 % k;
  while (r != 0) {
    r = r * 10 + 7;
    r %= k;
    ans++;
  }
  cout << ans << endl;

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

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int solve(int n, int k) {
  static vector<int> visited(k, 0);
  static int ans = 0;
  n %= k;
  if (visited[n] == 0) {
    visited[n]++;
    ans++;
    if (n == 0) {
      return ans;
    }
    return solve(n * 10 + 7, k);
  } else {
    return -1;
  }
}

int main() {
  int k;
  cin >> k;
  cout << solve(7, k) << endl;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int solve(int n, int k) {
  static vector<int> visited(k, 0);
  static int ans = 0;
  n %= k;
  printf("n  :%d\\n", n);
  printf("ans:%d\\n", ans);
  if (visited[n] == 0) {
    visited[n]++;
    ans++;
    if (n == 0) {
      return ans;
    }
    solve(n * 10 + 7, k);
  } else {
    return -1;
  }
}

int main() {
  int k;
  cin >> k;
  cout << solve(7, k) << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

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

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

  ll tmp = 10;
  ll sum = 7;
  ll ans = 1;
  ll cnt = 10000000;
  while (cnt--) {
    if (sum % k == 0) {
      cout << ans << endl;
      return 0;
    }
    ans++;
    ll add = 7;
    add = (add * tmp) % k;
    sum = (sum + add) % k;
    tmp = (tmp * 10) % k;
  }
  cout << -1 << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
#define INF 1LL << 30
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

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

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

  ll tmp = 10;
  ll sum = 7;
  ll ans = 1;
  while (1) {
    if (sum % k == 0) {
      cout << ans << endl;
      return 0;
    }
    ans++;
    ll add = 7;
    add = (add * tmp) % k;
    sum = (sum + add) % k;
    tmp = (tmp * 10) % k;
  }
}