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

#include <iostream>

int main() {

  unsigned long long N;
  std::cin >> N;

  unsigned long long amari = 0;
  unsigned long long last_amari = 7 % N;
  amari += last_amari;
  int cnt = 1;

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

  while (amari) {
    last_amari *= 10;
    last_amari %= N;
    amari += last_amari;
    amari %= N;
    cnt++;
  }

  std::cout << cnt << std::endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

int main() {

  unsigned long long N;
  std::cin >> N;

  unsigned long long amari = 0;
  unsigned long long last_amari = 7 % N;
  amari += last_amari;
  int cnt = 1;

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

  while (amari) {
    last_amari *= 10;
    last_amari %= N;
    amari += last_amari;
    amari %= N;
    cnt++;
  }

  std::cout << cnt << std::endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

int main() {
  long long K;
  std::cin >> K;
  int x = 0;
  int count;
  for (count = 0; count < K; count++) {
    x = (x * 10 + 7) % K;
    if (x == 0)
      break;
  }
  if (count == K)
    std::cout << -1 << std::endl;
  else
    std::cout << count + 1 << std::endl;
}


Error: TLE

Fixed submission:

#include <iostream>

int main() {
  long long K;
  std::cin >> K;
  if (K % 2 == 0) {
    std::cout << -1 << std::endl;
    return 0;
  }
  int x = 0;
  int count = 0;
  while (true) {
    x = (x * 10 + 7) % K;
    count++;
    if (x == 0)
      break;
  }
  std::cout << count << std::endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define MM(arr, x) memset(arr, x, sizeof(arr))
#define INF 0x3f3f3f3f
#define Maxn 1e5 + 10;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  ll ans = 0, k, now = 0;
  cin >> k;
  while (ans <= 99999999) {
    ans++;
    now = (now * 10 + 7) % k;
    if (now == 0) {
      cout << ans;
      return 0;
    }
  }
  cout << -1;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define MM(arr, x) memset(arr, x, sizeof(arr))
#define INF 0x3f3f3f3f
#define Maxn 1e5 + 10;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  ll ans = 0, k, now = 0;
  cin >> k;
  while (ans <= 999999999) {
    ans++;
    now = (now * 10 + 7) % k;
    if (now == 0) {
      cout << ans;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <string>
using namespace std;

int main() {
  int x;
  std::cin >> x;
  int k = 7 % x;
  for (int i = 0; i < x; i++) {
    if (k % x == 0) {
    std:
      cout << i + 1 << std::endl;
      return 0;
    }
    k = (10 * k + 7) % x;
  }
  std::cout << -1 << std::endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>
#define _USE_MATH_DEFINES
#include <algorithm>
#include <math.h>
#include <memory>
#include <string>
#define Rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
void swap(int &a, int &b) {
  int temp = a;
  a = b;
  b = temp;
  return;
}
double ncr(int n, int r) {
  int a = 1;
  Rep(i, r) a = (a * (n - i)) / (i + 1);
  return a;
}
double npr(double n, double r) {
  double a = 1;
  Rep(i, r) a *= n - (double)i;
  return a;
}
int mod(int a, int b) { return a % b; }

int main() {
  int k;
  std::cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    std::cout << -1 << std::endl;
    return 0;
  }
  int a = 0;
  for (long long i = 0; 1; i++) {
    int h = 7;
    for (int j = 0; j < i; j++) {
      h *= 10 % k;
      h = h % k;
    }
    a = (a + h) % k;
    // std::cout << a << std::endl;
    if (a == 0) {
      std::cout << i + 1 << std::endl;
      return 0;
    }
  }
  std::cout << -1 << std::endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int a[1000001];
int main() {
  int K;
  scanf("%d", &K);
  a[1] = 7 % K;
  for (int i = 2; i <= K; i++)
    a[i] = (a[i - 1] * 10 + 7) % K;

  for (int i = 1; i <= K; i++)
    if (a[i] == 0) {
      printf("%d\\n", i);
      return 0;
    }
  printf("-1\\n");
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  int k;
  cin >> k;
  int cnt = 1;
  int tmp1 = 1 % k, tmp2 = 0;
  if (!((k % 2) or (k % 5)))
    cnt = -1;
  else if (k == 7)
    cnt = 1;
  else {
    if (k % 7 == 0)
      k = k / 7;
    while (1) {
      tmp2 = (tmp1 + tmp2) % k;
      if (tmp2 == 0)
        break;
      tmp1 = (tmp1 * 10) % k;
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// #include<bits/stdc++.h>
#define PI 2 * acos(0.0)
#define pb push_back

using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;

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

  ll n;

  cin >> n;

  if (n % 2 == 0 || n % 5 == 0)
    cout << "-1" << endl;
  else {
    ll sum = 0;
    ll ans;
    for (ans = 1; ans <= n; ans++) {
      sum = (sum * 10 + 7) % n;
      if (sum == 0)
        break;
    }
    cout << ans << endl;
  }

  return 0;

  /***Israil Hosen
       Computer Science & Engineering
    University Of Rajshahi.
    ***/
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// #include<bits/stdc++.h>
#define PI 2 * acos(0.0)
#define pb push_back

using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;

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

  ll n;

  cin >> n;

  if (n % 2 == 0)
    cout << "-1" << endl;
  else {
    ll ans = 0;
    for (int i = 1;; i++) {

      ans = (10 * ans + 7);
      if (ans % n == 0) {
        cout << i << "\\n";
        break;
      }
    }
  }

  return 0;

  /***Israil Hosen
       Computer Science & Engineering
    University Of Rajshahi.
    ***/
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n, i, j, a, b, c, k, d;
  queue<ll> q;
  cin >> k;
  c = 1;
  if (k % 2 == 0)
    cout << "-1" << endl;
  else {
    n = 7;
    d = 0;
    q.push(d);
    while (n % k != 0) {
      if (n < k) {
        n = n * 10 + 7;
        c++;
      } else if (n >= k) {
        a = n % k;
        if (a != q.front()) {
          q.pop();
          q.push(a);
          c++;
        } else {
          d = 1;
        }
        n = a * 10 + 7;
      }
      if (d == 1 || c > 1000000)
        break;
    }
    if (d == 1 || c > 1000000)
      cout << "-1" << endl;
    else
      cout << c << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n, i, j, a, b, c, k, d;
  queue<ll> q;
  cin >> k;
  c = 1;
  if (k % 2 == 0)
    cout << "-1" << endl;
  else {
    n = 7;
    d = 0;
    q.push(d);
    while (n % k != 0) {
      if (n < k) {
        n = n * 10 + 7;
        c++;
      } else if (n >= k) {
        a = n % k;
        if (a != q.front()) {
          q.pop();
          q.push(a);
          c++;
        } else {
          d = 1;
        }
        n = a * 10 + 7;
      }
      if (d)
        break;
    }
    if (d)
      cout << "-1" << endl;
    else
      cout << c << endl;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
int main() {
  int a, sum = 0, b, c = 0;
  cin >> a;
  b = a;
  while (b) {
    b /= 10;
    c = c * 10 + 7;
    sum++;
  }
  while (c % a) {
    c = (c % a) * 10 + 7;
    sum++;
    if (sum >= 100000000) {
      cout << "-1";
      return 0;
    }
  }
  cout << sum;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
int main() {
  int a, sum = 0, b, c = 0;
  cin >> a;
  b = a;
  while (b) {
    b /= 10;
    c = c * 10 + 7;
    sum++;
  }
  if (c < a) {
    c = c * 10 + 7;
    sum++;
  }
  while (c % a) {
    c = (c % a) * 10 + 7;
    sum++;
  }
  cout << sum;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath>
#include <cstdlib> // abs(int)
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

#define roundup(n, d) (((n) + ((d)-1)) / (d))
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define FAST_IO                                                                \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(), v.end()

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;

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

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

  while (n % k > 0) {
    n = (n * 10 + 7) % k;
    count++;
  }
  cout << count << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath>
#include <cstdlib> // abs(int)
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

#define roundup(n, d) (((n) + ((d)-1)) / (d))
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i, n) for (long long i = 0; i < n; ++i)
#define FAST_IO                                                                \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(), v.end()

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;

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

  ll count = 1;
  ll n = 7;
  if (k % 2 == 0 && k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }

  while (n % k > 0) {
    n = (n * 10 + 7) % k;
    count++;
  }
  cout << count << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = a; i < (b); i++)

ll k;

void solve() {
  if (k % 2 == 0 || k % 5 == 0) {
    cout << "-1\\n";
    return;
  }
  ll ans = 1;
  ll cur = 7 % k;
  while (cur != 0) {
    cur = cur * 10 + 7;
    cur %= k;
    ans++;
  }
  cout << ans << "\\n";
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> k;
  solve();
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define FOR(i, a, b) for (int i = a; i < (b); i++)

ll n, dig, m;
vector<int> num, ans;

bool all_seven() {
  m = ans.size();
  FOR(i, 0, m) {
    if (ans[i] != 7)
      return 0;
  }
  return true;
}

void sumar() {
  m = ans.size();
  FOR(i, 0, m) {
    if (i < dig)
      ans[i] += num[i];
    if (ans[i] >= 10) {
      if (i == m - 1) {
        ans.push_back(ans[i] / 10);
        ans[i] %= 10;
      } else {
        ans[i + 1] += ans[i] / 10;
        ans[i] %= 10;
      }
    }
  }
}

void solve() {
  if (n % 10 == 2 || n % 10 == 4 || n % 10 == 5 || n % 10 == 6 || n % 10 == 8) {
    cout << -1;
    return;
  }
  while (n > 0) {
    ans.push_back(n % 10);
    num.push_back(n % 10);
    n /= 10;
    dig++;
  }
  m = ans.size();
  while (m <= 1000000) {
    if (all_seven()) {
      cout << m;
      return;
    } else {
      sumar();
      m = ans.size();
    }
  }
  cout << -1;
}

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

#include <iostream>
using namespace std;

int main() {
  int k;
  cin >> k;
  if (k % 7 == 0)
    k /= 7;
  int ans = 0;
  int ini = 1;
  if (k % 2 == 0 || k % 5 == 0)
    ans = -1;
  else
    while (ini) {
      ans++;
      // cout<<ini<<" ";
      ini = ini % k;
      // cout<<ini<<" ";
      if (ini == 0)
        break;
      ini *= 10;
      ini++;
    }
  cout << ans;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int k;
  cin >> k;
  if (k % 7 == 0)
    k /= 7;
  int ans = 0;
  int ini = 1;
  if (k % 2 == 0)
    ans = -1;
  else
    while (ini) {
      ans++;
      // cout<<ini<<" ";
      ini = ini % k;
      // cout<<ini<<" ";
      if (ini == 0)
        break;
      ini *= 10;
      ini++;
    }
  cout << ans;
  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 ans = 1;
  long long int r, q;
  r = 7 % K;
  q = 0;
  while (1) {
    if (r == 0) {
      cout << ans;
      break;
    } else if (K % 2 == 0 || K % 5 == 0 || r == q) {
      cout << -1;
      break;
    }
    q = r;
    r = (10 * r + 7) % K;
    ans += 1;
  }
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int K;
  cin >> K;
  int ans = 1;
  int r, q;
  r = 7 % K;
  q = 0;
  while (1) {
    if (r == 0) {
      cout << ans;
      break;
    } else if (r == q) {
      cout << -1;
      break;
    }
    q = r;
    r = (10 * r + 7) % K;
    ans += 1;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
int visit[10000010];
int main() {
  int k, temp = 7, flag = 0, ans = 1;
  memset(visit, 0, sizeof(visit));
  scanf("%d", &k);
  if (k % 2 == 0) {
    printf("-1\\n");
  } else {
    while (1) {
      if (temp % k == 0 && temp / k > 0) {
        break;
      } else if (visit[temp] == 1) {
        flag = -1;
        break;
      } else {
        visit[temp] = 1;
        temp = temp % k;
        temp = temp * 10 + 7;
        ans++;
      }
    }
    if (flag == -1) {
      printf("-1\\n");
    } else {
      printf("%d\\n", ans);
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;
int visit[10000010];
int main() {
  int k, temp = 7, flag = 0, ans = 1;
  memset(visit, 0, sizeof(visit));
  scanf("%d", &k);
  if (k % 2 == 0) {
    printf("-1\\n");
  } else {
    while (1) {
      //			printf("%d\\n",temp);
      if (temp % k == 0 && temp / k > 0) {
        break;
      } else if (visit[temp] == 1) {
        flag = -1;
        break;
      } else {
        temp = temp % k;
        temp = temp * 10 + 7;
        ans++;
      }
    }
    if (flag == -1) {
      printf("-1\\n");
    } else {
      printf("%d\\n", ans);
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T> void print(const T &v);

int main() {
  int k;
  cin >> k;
  set<ll> s;
  // if (k % 2 == 0)
  // {
  //     cout << -1 << endl;
  //     return 0;
  // }
  ll num = 7;
  for (int i = 1;; i++) {
    num %= k;
    if (num == 0) {
      cout << i << endl;
      return 0;
    }
    if (s.count(num)) {
      cout << -1 << endl;
      return 0;
    }
    s.insert(num);
    num = num * 10 + 7;
  }
}

// Use For Debug
template <typename T> void print(T const &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << ' ';
    cout << v[i];
  }
  cout << endl;
};

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T> void print(const T &v);

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll num = 7;
  for (int i = 1;; i++) {
    num %= k;
    if (num == 0) {
      cout << i << endl;
      return 0;
    }
    num = num * 10 + 7;
  }
}

// Use For Debug
template <typename T> void print(T const &v) {
  for (int i = 0; i < v.size(); i++) {
    if (i)
      cout << ' ';
    cout << v[i];
  }
  cout << endl;
};
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 mod = 0, ans = 1;
  for (;;) {

    mod *= 10;
    mod %= n;
    mod += 7;
    mod %= n;
    if (mod == 0) {
      cout << ans << endl;
      return 0;
    }
    ans++;
  }
}

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;
  }
  long long mod = 0, ans = 1;
  for (;;) {
    mod *= 10;
    mod %= n;
    mod += 7;
    mod %= n;
    if (mod == 0) {
      cout << ans << endl;
      return 0;
    }
    ans++;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

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

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

  int num = 0;
  int k = 1;
  int count = 0;
  while (true) {
    ++count;
    num += 7 * k;
    num %= K;
    if (num == 0)
      break;
    k *= 10;
    k %= K;
  }
  cout << count;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const int INF = 1 << 30;
const long long LINF = 1LL << 60;
const long long MOD = 1000000000 + 7;
const double PI = acos(-1);

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

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

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

///*Bismillahir Rahmanir Rahim***///
/***Stay_Home_Stay_Safe***/
///**Author Thasin Sheikh**///
#include <bits/stdc++.h>
using namespace std;
#define MAX 1e6 + 10
#define MOD 1000000007
#define PI 3.14159265359
#define makefast__ ios_base::sync_with_stdio(false);
using ll = long long int;
using dl = double;
const int N = 2e5 + 10;
ll aarray[200000 + 10];
ll magic[101][101];
vector<ll> v;
bool prime[1000001];
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  makefast__ string str;
  ll i, j, n, m, k, t;
  cin >> n;
  k = 0;
  i = 1;
  while (i <= 1e7) {
    k = ((10 * k) + 7) % n;
    if (k == 0) {
      cout << i << endl;
      return 0;
    }
    i++;
  }
  cout << -1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

///*Bismillahir Rahmanir Rahim***///
/***Stay_Home_Stay_Safe***/
///**Author Thasin Sheikh**///
#include <bits/stdc++.h>
using namespace std;
#define MAX 1e6 + 10
#define MOD 1000000007
#define PI 3.14159265359
#define makefast__ ios_base::sync_with_stdio(false);
using ll = long long int;
using dl = double;
const int N = 2e5 + 10;
ll aarray[200000 + 10];
ll magic[101][101];
vector<ll> v;
bool prime[1000001];
void gen() {
  ll i, j, l, k, n, m;
  for (i = 1; i <= 1000000; i++) {
    ll k = i;
    l = 0;
    while (k--) {
      l *= 10;
      l += 7;
    }
    v.push_back(l);
  }
}
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  makefast__ string str;
  ll i, j, n, m, k, t;
  gen();
  cin >> n;
  for (i = 0; i < v.size(); i++) {
    if (v[i] % n == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int check(int k) {
  int val = 7;
  int count = 1;
  while (val % k != 0) {
    val = (val % k) * 10 + 7;
    count++;
  }
  return count;
}
int main() {

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

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {

  long long k;
  cin >> k;
  if (k == 1) {
    cout << 1 << endl;
    return 0;
  } else if (k < 7) {
    cout << -1 << endl;
    return 0;
  } else {
    int occ = 1;
    string s = "7";
    int ans;
    for (int i = 1; i < 10000; i++) {
      s += "7";
      if (stoll(s) % k == 0) {
        ans = i + 1;
        cout << ans << endl;
        return 0;
      }
    }
    cout << -1 << endl;
  }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll k;
  ll num = 7;
  cin >> k;
  ll sum = 7LL % k;
  ll fac = 10LL % k;
  ll cnt = 1;
  while (sum % k && cnt <= 10000000) {
    sum += (num % k * fac) % k;
    num = num % k * fac;
    cnt++;
  }
  if (sum % k == 0) {
    cout << cnt << endl;
  } else {
    cout << -1 << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll k;
  ll num = 7;
  cin >> k;
  ll sum = 7LL % k;
  ll fac = 10LL % k;
  if (k % 2 != 0 && k != 5) {
    ll cnt = 1;
    while (sum % k) {
      sum += (num % k * fac) % k;
      num = (num % k * fac);
      cnt++;
    }
    cout << cnt << endl;
  } else {
    cout << -1 << endl;
  }
}