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


//
// Created by watemus on 08.09.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define FF first
#define SS second

using ll = long long;
using ld = long double;

#define int ll

template <typename T> using vec = std::vector<T>;

template <typename T> using uset = std::unordered_set<T>;

template <typename T1, typename T2> using umap = std::unordered_map<T1, T2>;

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;
const ld PI = acos(-1);

#ifdef LOCAL
std::mt19937 rnd(228);
#else
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
#endif

vec<pair<int, int>> DD = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
/*
template<class... Args>
auto Vec(size_t n, Args&&... args) {
  if constexpr(sizeof...(args) == 1)
    return vector(n, args...);
  else
    return vector(n, Vec(args...));
}*/

#ifdef LOCAL
#else
#endif

void run() {
  int n;
  cin >> n;
  if (n % 2 == 0 || n % 5 == 0) {
    cout << "-1\\n";
    return;
  }
  int cur = 0;
  for (int i = 1; i < 1e7; i++) {
    cur = ((cur * 10) + 7) % n;
    if (cur == 0) {
      cout << i << '\\n';
      return;
    }
  }
  cout << "-1\\n";
}

signed main() {
#ifdef LOCAL
  std::freopen("input.txt", "r", stdin);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
#endif
  int t = 1;
  // cin >> t;
  while (t--) {
    run();
  }
  return 0;
}


Error: TLE

Fixed submission:


//
// Created by watemus on 08.09.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define FF first
#define SS second

using ll = long long;
using ld = long double;

#define int ll

template <typename T> using vec = std::vector<T>;

template <typename T> using uset = std::unordered_set<T>;

template <typename T1, typename T2> using umap = std::unordered_map<T1, T2>;

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;
const ld PI = acos(-1);

#ifdef LOCAL
std::mt19937 rnd(228);
#else
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
#endif

vec<pair<int, int>> DD = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
/*
template<class... Args>
auto Vec(size_t n, Args&&... args) {
  if constexpr(sizeof...(args) == 1)
    return vector(n, args...);
  else
    return vector(n, Vec(args...));
}*/

#ifdef LOCAL
#else
#endif

void run() {
  int n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "-1\\n";
    return;
  }
  int cur = 0;
  for (int i = 1;; i++) {
    cur = ((cur * 10) + 7) % n;
    if (cur == 0) {
      cout << i << '\\n';
      return;
    }
  }
}

signed main() {
#ifdef LOCAL
  std::freopen("input.txt", "r", stdin);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
#endif
  int t = 1;
  // cin >> t;
  while (t--) {
    run();
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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


Error: TLE

Fixed submission:

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

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

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

int main() {
  long long K = 0;
  cin >> K;
  long long ans = 0;
  if (!(K % 2)) {
    cout << -1 << endl;
    return 0;
  }
  long long now = 0;
  vector<bool> A(K, 0);
  while (true) {
    now = 10 * now + 7;
    now %= K;
    if (A.at(now)) {
      cout << -1 << endl;
      return 0;
    }
    A.at(now) = 1;
    if (now) {
      ans++;
    } else {
      ans++;
      break;
    }
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long K = 0;
  cin >> K;
  long long ans = 0;
  if (!(K % 2)) {
    cout << -1 << endl;
    return 0;
  }
  long long now = 0;
  while (true) {
    now = 10 * now + 7;
    if (now % K) {
      now %= K;
      ans++;
    } else {
      ans++;
      break;
    }
  }

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

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

int main(int argc, char const *argv[]) {
  int k;
  cin >> k;

  vector<int> a(1000001);
  a[1] = 7;
  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] % k == 0) {
      cout << i << endl;
      return 0;
    }
  }

  cout << "-1" << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

int main(int argc, char const *argv[]) {
  int k;
  cin >> k;

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

  long long a = 7;
  long long ans = 1;
  while (a % k != 0) {
    a = (a * 10 + 7) % k;
    ans++;
  }

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

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

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

  ll res = 1;
  ll x = 7;
  while (true) {
    if (res == 2000000) {
      cout << "-1" << endl;
      break;
    }
    x %= k;
    if (x == 0) {
      cout << res << endl;
      break;
    }
    res++;
    x *= 10;
    x += 7;
  }
}

Error: TLE

Fixed submission:

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

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

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

#include <iostream>

using namespace std;

int main() {
  int K, sum = 0, count = 1;
  cin >> K;

  if (K % 2 == 0 || K % 5 == 0) {
    cout << "-1";
  } else {
    while (1) {
      sum = (7 + sum * 10) % K;
      if (sum % K == 0) {
        cout << count;
        break;
      }
      count++;
    }
  }
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int K, sum = 0, count = 1;
  cin >> K;

  if (K % 2 == 0 || K % 5 == 0) {
    cout << "-1";
  } else {
    while (1) {
      sum = 7 + sum * 10;
      if (sum % K == 0) {
        cout << count;
        break;
      }
      count++;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int mod[1000010];

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (k == 7 || k == 1) {
    cout << 1 << endl;
    return 0;
  }
  mod[1] = 7 % k;
  for (int i = 2;; i++) {
    mod[i] = mod[i - 1] * 10 % k + mod[1];
    mod[i] %= k;
    if (mod[i] == 0) {
      cout << i << endl;
      return 0;
    }
    if (i >= 1000000) {
      cout << -1 << endl;
      return 0;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
const int MOD = 1e9 + 7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int mod[1000001];

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (k == 7) {
    cout << 1 << endl;
    return 0;
  }
  mod[1] = 7 % k;
  for (int i = 2;; i++) {
    mod[i] = mod[i - 1] * 10 % k + mod[1];
    mod[i] %= k;
    if (mod[i] == 0) {
      cout << i << endl;
      return 0;
    }
  }
  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, c = 1;

  cin >> k;
  // vector<int> x(n), y(n);
  int s = 7;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (s % k != 0) {
    s = s % k * 10 + 7;
    c = c + 1;
  }

  cout << c << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

  cin >> k;
  // vector<int> x(n), y(n);
  int s = 7;
  if (k % 2 == 0 && k % 5 == 5) {
    cout << -1 << endl;
    return 0;
  }
  while (s % k != 0) {
    s = s % k * 10 + 7;
    c = c + 1;
  }

  cout << c << 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() {
  ll K, count = 1;
  cin >> K;
  ll mod = 7 % K;
  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  while (mod > 0) {
    mod = (mod * 10 + 7) % K;
    count++;
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

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

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

#include <iostream>

using namespace std;

int main() {
  long long K, p = 0, c = 0;
  cin >> K;
  if (K % 2 == 0 || K % 5 == 0)
    cout << "-1";
  else {
    do {
      p = (p * 10 + 7) % K;
      ++c;
    } while (p);
    cout << c;
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {
  long long K;
  int c = 0, t, p = 0;
  cin >> K;
  if (K % 2 == 0 || K % 5 == 0)
    cout << "-1";
  else {
    do {
      p = p * 10 + 7;
      t = p % K;
      ++c;
    } while (t);
    cout << c;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  ll K;
  cin >> K;
  if (K == 2 || K == 5) {
    cout << -1 << endl;
    return 0;
  }
  ll ten[3000000];
  ten[0] = 7;
  for (int i = 1; i < 3000000; i++) {
    ten[i] = (ten[i - 1] * 10) % K;
  }
  ll now = 0;
  ll ans = 0;
  for (ans = 0; ans < 3000000;) {
    now += ten[ans];
    now %= K;
    ans++;
    if (now == 0) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  ll K;
  cin >> K;
  if (K == 2 || K == 5) {
    cout << -1 << endl;
    return 0;
  }
  ll ten[3000000];
  ten[0] = 7;
  for (int i = 1; i < 3000000; i++) {
    ten[i] = (ten[i - 1] * 10) % K;
  }
  ll now = 0;
  ll ans = 0;
  while (0 == 0) {
    now += ten[ans];
    now %= K;
    ans++;
    if (now == 0) {
      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;

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

Error: TLE

Fixed submission:

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

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

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

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

int main() {

  long long int K, amari = 0, ba;

  std::cin >> K;

  if (K % 2 == 0) {
    cout << -1;
  } else {
    long long int i = 0;
    while (1) {
      i++;
      ba = amari;
      amari = (amari * 10 + 7) % K;
      if (amari == 0) {
        cout << i << endl;
        break;
      }
      if (amari == ba) {
        cout << -1 << endl;
        break;
      }
      if (i > K + 10) {
        cout << -1 << endl;
        break;
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

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

int main() {

  long long int K, amari = 0, ba;

  std::cin >> K;

  if (K % 2 == 0) {
    cout << -1;
  } else {
    long long int i = 0;
    while (1) {
      i++;
      ba = amari;
      amari = (amari * 10 + 7) % K;
      if (amari == 0) {
        cout << i << endl;
        break;
      }
      if (amari == ba) {
        cout << -1 << endl;
        break;
      }
    }
  }

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

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

long long modAdd(long long a, long long b, long long mod) {
  return ((a % mod) + (b % mod)) % mod;
}

long long modSub(long long a, long long b, long long mod) {
  long long c = ((a % mod) - (b % mod)) % mod;
  return ((c < 0) ? c + mod : c);
}
long long modMul(long long a, long long b, long long mod) {
  return ((a % mod) * (b % mod)) % mod;
}

long long modPow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) {
      res = modMul(res, a, mod);
    }
    a = modMul(a, a, mod);
    n >>= 1;
  }
  return res;
}

long long modDiv(long long a, long long b, long long mod) {
  return modMul(a, modPow(b, mod - 2, mod), mod);
}

long long modCombination(long long n, long long r, long long mod) {
  if (r > n / 2)
    return modCombination(n, n - r, mod);
  long long res = 1;
  for (long long i = 1; i <= r; i++) {
    res = modMul(res, n - i + 1, mod);
    res = modDiv(res, i, mod);
  }
  return res;
}

int main() {
  long long k;
  cin >> k;
  vector<long long> m;
  int n = 0;
  m.push_back(7);
  if (k % 2 == 0) {
    cout << -1 << endl;
  } else {
    while (true) {
      if (m[n] % k == 0)
        break;
      m.push_back(modAdd(m[n], modMul(7, modPow(10, n + 1, k), k), k));
      n++;
      if (n >= 1000000)
        n = -2;
    }
    cout << n + 1 << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

long long modAdd(long long a, long long b, long long mod) {
  return ((a % mod) + (b % mod)) % mod;
}

long long modSub(long long a, long long b, long long mod) {
  long long c = ((a % mod) - (b % mod)) % mod;
  return ((c < 0) ? c + mod : c);
}
long long modMul(long long a, long long b, long long mod) {
  return ((a % mod) * (b % mod)) % mod;
}

long long modPow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) {
      res = modMul(res, a, mod);
    }
    a = modMul(a, a, mod);
    n >>= 1;
  }
  return res;
}

long long modDiv(long long a, long long b, long long mod) {
  return modMul(a, modPow(b, mod - 2, mod), mod);
}

long long modCombination(long long n, long long r, long long mod) {
  if (r > n / 2)
    return modCombination(n, n - r, mod);
  long long res = 1;
  for (long long i = 1; i <= r; i++) {
    res = modMul(res, n - i + 1, mod);
    res = modDiv(res, i, mod);
  }
  return res;
}

int main() {
  long long k;
  cin >> k;
  vector<long long> m;
  int n = 0;
  m.push_back(7);
  if (k % 2 == 0) {
    cout << -1 << endl;
  } else {
    while (true) {
      if (m[n] % k == 0)
        break;
      m.push_back(modAdd(m[n], modMul(7, modPow(10, n + 1, k), k), k));
      n++;
    }
    cout << n + 1 << endl;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0)
    return cout << -1, 0;
  string s = "7";
  long long cur_power = 1, cur = 7;
  while (cur % k != 0) {
    cur_power = cur_power * 10 % k;
    cur = cur + 7 * cur_power % k;
    cur %= k;
    s += '7';
    if (s.size() > k)
      return cout << -1, 0;
  }
  cout << s.size();
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0)
    return cout << -1, 0;
  string s = "7";
  long long cur_power = 1, cur = 7;
  while (cur % k != 0) {
    cur_power = cur_power * 10 % k;
    cur = cur + 7 * cur_power % k;
    cur %= k;
    s += '7';
  }
  cout << s.size();
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

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

  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
  ll k;
  ll a = 7;
  for (int i = 0; i <= k; i++) {
    if (a % k == 0) {
      cout << i + 1 << endl;
      return 0;
    }
    a = (a * 10 + 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() {
  long long int n;
  cin >> n;
  long long int ans = 0, val = 0, count = 0;
  for (int i = 1; i <= 1000000; ++i) {
    val = val * 10 + 7;
    val = val % n;
    count++;
    if (val == 0) {
      ans = 1;
      break;
    }
  }
  (ans == 1) ? cout << count : cout << -1;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  long long int k = 7, count = 0;
  while (1) {
    if (n % 2 == 0)
      break;
    count++;
    if (k % n == 0)
      break;
    k *= 10;
    k += 7;
  }
  (count != 0) ? cout << count : cout << -1;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

// ヘッダー
#include <bits/stdc++.h>
using namespace std;

// 型定義
typedef long long ll;

// 定数
const int INF = 1e+9;
const int MOD = 1e+9 + 7;

// REPマクロ
#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 REP2(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define REPD2(i, a, b) for (ll i = a; i > (ll)(b); i--)

// 多次元 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...));
}

// vectorの扱い
#define ALL(x) (x).begin(), (x).end() // sortなどの引数省略
#define SIZE(x) ((ll)(x).size())      // size
#define MAX(x) *max_element(ALL(x))   // 最大値
#define MIN(x) *min_element(ALL(x))   // 最小値

// xのn乗%modを計算
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ll K;
  cin >> K;
  ll ans = 1;
  ll num = 7;

  if (K % 2 == 0) {
    ans = -1;
  } else {
    ans = 1;
    num = 7;
    while (num % K != 0) {
      num += 7 * mod_pow(10, ans, K);
      num %= K;
      ans++;
      if (ans > 2000000)
        break;
    }
    if (num % K != 0)
      ans = -1;
  }

  cout << ans << endl;
}

Error: TLE

Fixed submission:

// ヘッダー
#include <bits/stdc++.h>
using namespace std;

// 型定義
typedef long long ll;

// 定数
const int INF = 1e+9;
const int MOD = 1e+9 + 7;

// REPマクロ
#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 REP2(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define REPD2(i, a, b) for (ll i = a; i > (ll)(b); i--)

// 多次元 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...));
}

// vectorの扱い
#define ALL(x) (x).begin(), (x).end() // sortなどの引数省略
#define SIZE(x) ((ll)(x).size())      // size
#define MAX(x) *max_element(ALL(x))   // 最大値
#define MIN(x) *min_element(ALL(x))   // 最小値

// xのn乗%modを計算
ll mod_pow(ll x, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  ll K;
  cin >> K;
  ll ans = 1;
  ll num = 7;
  if (K % 2 == 0) {
    ans = -1;
  } else {
    while (num % K != 0) {
      num += 7 * mod_pow(10, ans, K);
      num %= K;
      ans++;
    }
  }

  cout << ans << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

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

// --------------------------------------------------------------------------------
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mset(arr, val) memset(arr, val, sizeof(arr))
#define frepi(a, b) for (int i = a; i <= b; ++i)
// --------------------------------------------------------------------------------

void solve_main() {
  int n;
  cin >> n;
  int total = 0;
  for (int i = 0; i <= 1e7; ++i) {
    total = (total * 10 + 7) % n;
    if (total == 0) {
      cout << i + 1 << "\\n";
      return;
    }
  }
  cout << "-1\\n";
}

int main() {
  // #ifndef ONLINE_JUDGE
  // 	freopen("/home/suryakant/input.txt","r",stdin);
  // 	freopen("/home/suryakant/output.txt","w",stdout);
  // #endif

  int t = 1;
  // cin>>t;
  while (t--) {
    solve_main();
  }
}

Error: WA

Fixed submission:

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

// --------------------------------------------------------------------------------
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define ll long long
#define mset(arr, val) memset(arr, val, sizeof(arr))
#define frepi(a, b) for (int i = a; i <= b; ++i)
// --------------------------------------------------------------------------------

void solve_main() {
  int n;
  cin >> n;
  int total = 0;
  for (int i = 0; i <= 1e7; ++i) {
    total = (total * 10 + 7) % n;
    if (total == 0) {
      cout << i + 1 << "\\n";
      return;
    }
  }
  cout << "-1\\n";
}

int main() {
#ifndef ONLINE_JUDGE
  freopen("/home/suryakant/input.txt", "r", stdin);
  freopen("/home/suryakant/output.txt", "w", stdout);
#endif

  int t = 1;
  cin >> t;
  while (t--) {
    solve_main();
  }
}