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

/*input

*/

#include <bits/stdc++.h>
#include <unistd.h>

#define rep(i, j, n) for (i = j; i < n; i++)
#define repi(i, j, n) for (i = j; i > n; i--)
#define inf 1e18
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define pb push_back
#define F first
#define S second
#define endl '\\n'
#define UQ(x) (x).resize(distance((x).begin(), unique(x.begin(), x.end())))

using namespace std;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64
    rnd64(chrono::high_resolution_clock::now().time_since_epoch().count());

ll power(ll a, ll m, ll mod) {
  ll ans = 1;
  while (m) {
    if (m % 2)
      ans *= a, ans %= (mod);
    a = (a * a) % (mod);
    m >>= 1;
  }
  return ans;
}

void init(ll *a, ll n, ll val) {
  for (ll i = 0; i < n; i++)
    a[i] = val;
}

void solve() {
  ll i, j, _;
  ll n;
  cin >> n;
  if (!(n % 2)) {
    cout << -1 << endl;
    return;
  }
  ll ans = 1, now = 7 % n;
  const ll t = 1e7;
  while (now && ans < t) {
    ++ans;
    now *= 10;
    now += 7;
    now %= n;
  }
  if (ans == t)
    ans = -1;
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
  return 0;
}


Error: TLE

Fixed submission:

/*input

*/

#include <bits/stdc++.h>
#include <unistd.h>

#define rep(i, j, n) for (i = j; i < n; i++)
#define repi(i, j, n) for (i = j; i > n; i--)
#define inf 1e18
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define pb push_back
#define F first
#define S second
#define endl '\\n'
#define UQ(x) (x).resize(distance((x).begin(), unique(x.begin(), x.end())))

using namespace std;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64
    rnd64(chrono::high_resolution_clock::now().time_since_epoch().count());

ll power(ll a, ll m, ll mod) {
  ll ans = 1;
  while (m) {
    if (m % 2)
      ans *= a, ans %= (mod);
    a = (a * a) % (mod);
    m >>= 1;
  }
  return ans;
}

void init(ll *a, ll n, ll val) {
  for (ll i = 0; i < n; i++)
    a[i] = val;
}

void solve() {
  ll i, j, _;
  ll n;
  cin >> n;
  if (!(n % 2)) {
    cout << -1 << endl;
    return;
  }
  ll ans = 1, now = 7 % n;
  while (now) {
    ++ans;
    now *= 10;
    now += 7;
    now %= n;
  }
  cout << ans << endl;
}

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

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

#define debug(val) "[ " << #val " : " << (val)
#define space " "
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1) * 4)
#define pb push_back
#define pi pair<int, int>
#define ff first
#define ss second
#define INF 2000000000
#define delta 0.0000000001
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};
const int Mod = 1000 * 1000 * 1000 + 7;

vll mul_mat(vll a, vll b) {
  vll res(2, vl(2, 0));
  int n = 2;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        res[i][j] += a[i][k] * b[k][j];
        res[i][j] %= Mod;
      }
    }
  }

  return res;
}

ll powmod(ll a, ll b, ll mod) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
      res %= mod;
    }
    b >>= 1;
    a = a * a;
    a %= mod;
  }
  return res;
}

void solve() {
  ll n;
  cin >> n;
  ll com = 0;
  for (ll i = 0; i <= 2000000; i++) {
    ll f = powmod(2, i, n);
    ll s = powmod(5, i, n);
    ll t = 7;
    com += (f * s * t);
    com %= n;
    if (com == 0) {
      cout << i + 1 << endl;
      return;
    }
  }
  cout << -1 << endl;
}

int main() {
#ifdef _DEBUG
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0); // FAST IO
  int q = 1;
  // cin >> q;
  for (int i = 1; i <= q; i++) {
    solve();
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;

#define debug(val) "[ " << #val " : " << (val)
#define space " "
#define vi vector<int>
#define vl vector<ll>
#define vll vector<vector<ll>>
#define vii vector<vector<int>>
#define PI (double)(atan(1) * 4)
#define pb push_back
#define pi pair<int, int>
#define ff first
#define ss second
#define INF 2000000000
#define delta 0.0000000001
vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};
const int Mod = 1000 * 1000 * 1000 + 7;

vll mul_mat(vll a, vll b) {
  vll res(2, vl(2, 0));
  int n = 2;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 2; j++) {
      for (int k = 0; k < 2; k++) {
        res[i][j] += a[i][k] * b[k][j];
        res[i][j] %= Mod;
      }
    }
  }

  return res;
}

ll powmod(ll a, ll b, ll mod) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a;
      res %= mod;
    }
    b >>= 1;
    a = a * a;
    a %= mod;
  }
  return res;
}

void solve() {
  ll n;
  cin >> n;
  ll com = 0;
  for (ll i = 0; i <= 5000000; i++) {
    ll f = powmod(2, i, n);
    ll s = powmod(5, i, n);
    ll t = 7;
    com += (f * s * t);
    com %= n;
    if (com == 0) {
      cout << i + 1 << endl;
      return;
    }
  }
  cout << -1 << endl;
}

int main() {
#ifdef _DEBUG
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0); // FAST IO
  int q = 1;
  // cin >> q;
  for (int i = 1; i <= q; i++) {
    solve();
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main() {
  int K;
  cin >> K;

  int ans = 0;
  ll ct = 7;
  ll md = 0;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    md += ct % K;
    ct *= 10;
    ct %= K;
    ans++;
    if (md % K == 0)
      break;
    if (ans >= 1e7) {
      ans = -1;
      break;
    }
  }

  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main() {
  int K;
  cin >> K;

  int ans = 0;
  ll ct = 7;
  ll md = 0;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (1) {
    md += ct % K;
    ct *= 10;
    ct %= K;
    ans++;
    if (md % K == 0)
      break;
  }

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

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

int main(void) {
  ll K;
  cin >> K;
  ll ans = 1;
  if (K % 2 == 0) {
    cout << -1 << endl;
    return 0;
  } else {
    int x = 7 % K;
    for (int i = 0; i < K; i++) {
      if (x == 0) {
        cout << ans << endl;
        return 0;
      } else {
        x = x * 10 + 7;
        x = x % K;
        ans++;
      }
    }
  }
  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;
using ll = long long;

int main(void) {
  ll K;
  cin >> K;
  ll ans = 0;
  if (K % 2 == 0)
    ans = -1;
  else {
    for (ll i = 0; i < 1000000; i++) {
      ll seq = 0;
      ll t = i;
      while (t >= 0)
        seq += 7 * pow(10, t--);
      if (seq % K == 0) {
        ans = i + 1;
        break;
      }
    }
  }
  cout << ans << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << "\\n";
    return 0;
  }
  int now = 0;
  for (int i = 1; i <= 1e8; i++) {
    now = (10 * now + 7) % K;
    if (now == 0) {
      cout << i << "\\n";
      return 0;
    }
  }
  cout << -1 << "\\n";
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int K;
  cin >> K;
  if (K % 2 == 0) {
    cout << -1 << "\\n";
    return 0;
  }
  int now = 0;
  for (int i = 1; i <= 1e8; i++) {
    now = (10 * now + 7) % K;
    if (now == 0) {
      cout << i << "\\n";
      return 0;
    }
  }
  assert(false);
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

const ll INF = 1LL << 62;
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;
}
// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;

int main() {
  ll K;
  cin >> K;
  int ans = 1;
  ll now = 7;
  set<ll> exist;
  exist.insert(now);
  while (now % K != 0) {
    now = (now * 10 + 7) % K;
    ans++;
    if (exist.count(now) > 0) {
      cout << -1 << endl;
      return 0;
    } else {
      exist.insert(now);
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

const ll INF = 1LL << 62;
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;
}
// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;

int main() {
  ll K;
  cin >> K;
  int ans = 1;
  ll now = 7;
  while (now % K != 0) {
    now = (now * 10 + 7) % K;
    ans++;
  }

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

#include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
const int maxn = 1e6 + 7;
int n = 0, q = 0;

struct Query {
  int id, l, r;
  bool operator<(Query a) const { return r < a.r; }
} query[maxn];

int v[maxn], sum[maxn], ans[maxn];

int lowbit(int x) { return x & (-x); }

void change(int i, int a) {
  while (i <= n) {
    sum[i] += a;
    i += lowbit(i);
  }
}

int getsum(int i) {
  int sum_t = 0;
  while (i > 0) {
    sum_t += sum[i];
    i -= lowbit(i);
  }
  return sum_t;
}
#define ll long long
int main() {
  ll k;
  cin >> k;
  ll tmp = 0;
  ll ans = 0;
  map<ll, ll> mp;
  int cnt = 100000000;
  while (cnt--) {
    ans = ans * 10ll + 7;
    tmp++;
    ans %= k;
    if (ans == 0)
      return cout << tmp << endl, 0;
  }
  cout << -1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
const int maxn = 1e6 + 7;
int n = 0, q = 0;

struct Query {
  int id, l, r;
  bool operator<(Query a) const { return r < a.r; }
} query[maxn];

int v[maxn], sum[maxn], ans[maxn];

int lowbit(int x) { return x & (-x); }

void change(int i, int a) {
  while (i <= n) {
    sum[i] += a;
    i += lowbit(i);
  }
}

int getsum(int i) {
  int sum_t = 0;
  while (i > 0) {
    sum_t += sum[i];
    i -= lowbit(i);
  }
  return sum_t;
}
#define ll long long
int main() {
  ll k;
  cin >> k;
  ll tmp = 0;
  ll ans = 0;
  map<ll, ll> mp;
  while (1) {
    ans = ans * 10ll + 7;
    tmp++;
    ans %= k;
    if (ans == 0)
      return cout << tmp << endl, 0;
    if (mp[ans])
      return cout << -1 << endl, 0;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

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

  int mod = 7 % K;
  int answer = 1;
  int count = 1;
  while (mod != 0) {
    count++;
    if (count > K) {
      std::cout << -1 << std::endl;
      return 0;
    }
    answer++;
    mod = (10 * mod + 7) % K;
  }

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

Error: TLE

Fixed submission:

#include <iostream>

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

  int mod = 7 % K;
  int answer = 1;
  int count = 1;
  while (mod != 0) {
    count++;
    if (count == K + 1) {
      std::cout << -1 << std::endl;
    }
    answer++;
    mod = (10 * mod + 7) % K;
  }

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

#include <bits/stdc++.h>
#include <math.h>

using namespace std;

template <typename T> long long modpow(const T n, const T p, const T mod);
template <typename T> long long modinv(const T n, const T mod);
template <typename T> bool chmax(T &a, const T &b);
template <typename T> bool chmin(T &a, const T &b);

long long inf = 1000000007;

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

  while (true) {
    ans++;
    hoge *= 10;
    hoge += 7;
    if (hoge % k == 0) {
      cout << ans << endl;
      return 0;
    }
    hoge %= k;

    if (ans >= 1000000) {
      cout << -1 << endl;
      return 0;
    }
  }

  return 0;
}

template <typename T> long long modpow(const T n, const T p, const T mod) {
  if (p == 0)
    return 1;
  if (p % 2 == 0) {
    long long a = modpow(n, p / 2, mod);
    return a * a % mod;
  }
  if (p % 2 == 1)
    return (modpow(n, p - 1, mod) * n) % mod;
  cerr << "ERROR" << endl;
  return 1;
}

template <typename T> long long modinv(const T n, const T mod) {
  return modpow(n, mod - 2, mod);
}

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <math.h>

using namespace std;

template <typename T> long long modpow(const T n, const T p, const T mod);
template <typename T> long long modinv(const T n, const T mod);
template <typename T> bool chmax(T &a, const T &b);
template <typename T> bool chmin(T &a, const T &b);

long long inf = 1000000007;

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

  while (true) {
    ans++;
    hoge *= 10;
    hoge += 7;
    if (hoge % k == 0) {
      cout << ans << endl;
      return 0;
    }
    hoge %= k;
  }

  return 0;
}

template <typename T> long long modpow(const T n, const T p, const T mod) {
  if (p == 0)
    return 1;
  if (p % 2 == 0) {
    long long a = modpow(n, p / 2, mod);
    return a * a % mod;
  }
  if (p % 2 == 1)
    return (modpow(n, p - 1, mod) * n) % mod;
  cerr << "ERROR" << endl;
  return 1;
}

template <typename T> long long modinv(const T n, const T mod) {
  return modpow(n, mod - 2, mod);
}

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

template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#define int long long

using namespace std;

int dp[100005];

signed main() {
  int q = 1;
  // cin>>q;
  while (q--) {
    int k;
    cin >> k;
    int count = 0, s = 0;
    if (k % 2 == 0) {
      cout << "-1";
      return 0;
    }
    while (count < 2 * (1e7)) {
      count++;
      s = (s * 10 + 7) % k;
      // cout<<s<<"\\n";
      if (s % k == 0)
        break;
    }
    if (count == 2 * (1e7))
      cout << -1 << "\\n";
    else
      cout << count << "\\n";
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#define int long long

using namespace std;

int dp[100005];

signed main() {
  int q = 1;
  // cin>>q;
  while (q--) {
    int k;
    cin >> k;
    int count = 0, s = 0;
    if (k % 2 == 0) {
      cout << "-1";
      return 0;
    }
    while (1) {
      count++;
      s = (s * 10 + 7) % k;
      if (s % k == 0)
        break;
    }
    cout << count << "\\n";
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
constexpr ll mod = 1000000007;
constexpr int inf = 1000000000;
constexpr ll linf = 1000000000000000000;

int main() {
  int k;
  cin >> k;
  int r = 0;
  bool b[k] = {};
  for (int i = 1;; ++i) {
    r = (10 * r + 7) % k;
    if (r == 0) {
      cout << i << endl;
      return 0;
    } else if (b[r]) {
      cout << -1 << endl;
      return 0;
    }
    b[r] = true;
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
constexpr ll mod = 1000000007;
constexpr int inf = 1000000000;
constexpr ll linf = 1000000000000000000;

int main() {
  int k;
  cin >> k;
  int r = 7 % k;
  for (int i = 1;; ++i) {
    if (r == 0) {
      cout << i << endl;
      return 0;
    }
    r = (10 * r + 7) % k;
    if (r == 7 % k) {
      cout << -1 << endl;
      return 0;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int64_t k;
  cin >> k;
  if (k % 2 == 0 or k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int64_t res = 0, cnt = 0;
  while (true) {
    // cout << cnt << " " << res << endl;
    res = (res * 10 + 7) % k;
    cnt++;
    if (res == 0)
      break;
  }
  cout << cnt << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

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

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

  ll x = 7 % K;

  for (int i = 1; i <= K; ++i) {
    if (x == 0) {
      cout << i << endl;
      exit(0);
    }

    x = (x * 10 + 7) % K;
  }
  cout << -1 << endl;
}


Error: TLE

Fixed submission:

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

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

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

  ll i = 1;
  while (1) {
    ll tmp = K * i;
    ++i;
    string s = to_string(tmp);
    bool ng = true;
    for (int i = 0; i < s.length(); ++i) {
      if (s[i] != '7') {
        ng = false;
        break;
      }
    }

    if (ng == true) {
      // cout << "tmp= " << tmp << endl;
      cout << s.length() << endl;
      exit(0);
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
// #define int long long
#define ar array<int, 2>
#define inf 1000000000000000000
int mod = 1e9 + 7;
int min(int a, int b) { return (a < b) ? a : b; }
int max(int a, int b) { return (a > b) ? a : b; }
int fp(int a, int b) {
  if (b == 0)
    return 1;
  int x = fp(a, b / 2);
  x = (x * x) % mod;
  if (b & 1)
    x = (x * a) % mod;
  return x;
}

const int N = 1e6 + 5;
int mp[N] = {0};

void solve() {

  int k;
  cin >> k;
  int x = 7;

  int ct = 0, ans = -1;
  while (1) {
    ct++;
    x %= k;
    // cout<<x<<endl;
    if (x == 0) {
      ans = ct;
      break;
    }

    if (mp[x])
      break;
    mp[x] = 1;
    x *= 10;
    x += 7;
  }
  cout << ans;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define endl "\\n"
// #define int long long
#define ar array<int, 2>
#define inf 1000000000000000000
int mod = 1e9 + 7;
int min(int a, int b) { return (a < b) ? a : b; }
int max(int a, int b) { return (a > b) ? a : b; }
int fp(int a, int b) {
  if (b == 0)
    return 1;
  int x = fp(a, b / 2);
  x = (x * x) % mod;
  if (b & 1)
    x = (x * a) % mod;
  return x;
}

const int N = 1e6 + 5;
int mp[N] = {0};

void solve() {
  int k;
  cin >> k;
  int x = 7;

  int ct = 0, ans = -1;
  while (1) {
    ct++;
    while (x >= k)
      x -= k;

    if (x == 0) {
      ans = ct;
      break;
    }

    if (mp[k])
      break;
    mp[x] = 1;
    x *= 10;
    x += 7;
  }
  cout << ans;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve();
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>

using namespace std;
#define ll long long int

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

  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  ll count = 1, num = 7;
  while (num % n) {
    num %= n;
    num *= 10;
    num += 7;
    count++;
    if (count > n) {
      cout << "-1" << endl;
      return 0;
    }
    // cout<<num<<endl;
  }
  cout << count << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>

using namespace std;
#define ll long long int

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

  ll n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1" << endl;
    return 0;
  }
  ll count = 1, num = 7;
  while (num % n) {
    num %= n;
    num *= 10;
    num += 7;
    count++;
    // cout<<num<<endl;
  }
  cout << count << endl;
  return 0;
}