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

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

int main(void) {
  long long k;
  cin >> k;
  long long l = 9 * k;
  if (k % 7 == 0)
    l /= 7;
  long long ans = -1;
  if (l % 2 != 0 && l % 5 != 0) {
    long long left = 1;
    for (long long i = 0; i < l; i++) {
      left = (left * 10) % l;
      if (left == 1) {
        ans = i + 1;
        break;
      }
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main(void) {
  long long k;
  cin >> k;
  long long left = 7 % k;
  long long left_n;
  int d = 1;
  while (left > 0) {
    left_n = (left * 10 + 7) % k;
    if (left_n == left) {
      d = -1;
      break;
    } else {
      d++;
      left = left_n;
    }
  }
  cout << d << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for (ll i = (k); i < (n); i++)
#define FORe(i, k, n) for (ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for (ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for (ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

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

  ll n = 7 % k;
  REP(i, k) {
    if (n == 0) {
      cout << i + 1 << endl;
      return 0;
    } else {
      n = (n * 10 + 7) % k;
    }
  }
  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for (ll i = (k); i < (n); i++)
#define FORe(i, k, n) for (ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for (ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for (ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

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

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

//
// Created by Sakurayama Kazuhiro on 2020/08/02.
//

#include <iostream>
#include <math.h> /* pow */
#include <set>

using namespace std;
int main() {
  unsigned int K;
  cin >> K;

  unsigned int cnt = 0;
  unsigned int a = 7;

  std::set<unsigned long long> myset;
  bool solved = false;

  while (true) {
    unsigned int aa = a % K;
    if (aa == 0) {
      solved = true;
      break;
    }
    if (myset.find(aa) != myset.end())
      break;
    myset.insert(aa);
    cnt++;
    a = (unsigned int)aa * 10 + 7;
  }

  if (solved) {
    cout << cnt + 1 << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:


#include <iostream>
#include <math.h> /* pow */

using namespace std;
int main() {
  long long int K;
  cin >> K;

  if (K % 2 == 0 || K % 5 == 0)
    cout << "-1" << endl;
  if (K % 7 == 0)
    K /= 7;

  int amari = 0;
  int cnt = 0;
  int buf = 1;
  while (true) {
    buf %= K;
    amari += buf;
    amari %= K;
    if (amari == 0) {
      break;
    }
    cnt++;
    buf *= 10;
  }

  cout << cnt + 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;
  if (k % 2 == 0) {
    printf("-1");
    return 0;
  }
  int remind = 7 % k, number = 1;
  while (remind) {
    ++number;
    remind = (remind * 10 + 7) % k;
    if (number > 1000000) {
      cout << "-1" << endl;
      return 0;
    }
  }
  printf("%d\\n", number);
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int k;
  cin >> k;
  if (k % 2 == 0) {
    printf("-1");
    return 0;
  }
  int remind = 7 % k, number = 1;
  while (remind) {
    ++number;
    remind = (remind * 10 + 7) % k;
  }
  printf("%d\\n", number);
  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)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
using namespace std;
#define int long long int
//------------ATCODER TEMPLATE-------------

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

  int sum = 0;
  int a = 7;
  for (int i = 0; i < 100000000; ++i) {
    sum += a;
    a = (a * 10) % K;
    sum %= K;

    if (sum % K == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
using namespace std;
#define int long long int
//------------ATCODER TEMPLATE-------------

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

  int sum = 0;
  int a = 7;
  for (int i = 0; i < 1000000000; ++i) {
    sum += a;
    a = (a * 10) % K;
    sum %= K;

    if (sum % K == 0) {
      cout << i + 1 << endl;
      break;
    }
  }
  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;
using P = pair<int, int>;

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

  int cnt = 1;
  int r = 7;
  map<int, int> check;
  while (true) {
    if (r % k == 0)
      break;
    if (check[r] > 0) {
      cout << -1 << endl;
      return;
    }
    check[r]++;
    r = r * 10 + 7;
    r %= k;
    cnt++;
  }

  cout << cnt << endl;
}

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


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;
using P = pair<int, int>;

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

  int cnt = 1;
  int r = 7;
  map<int, int> check;
  while (true) {
    if (r % k == 0)
      break;
    if (check[r] > 0) {
      cout << -1 << endl;
    }
    check[r]++;
    r = r * 10 + 7;
    r %= k;
    cnt++;
  }

  cout << cnt << endl;
}

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


//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

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

  ll ans = 0;

  ll n = 7;
  while (1) {
    ans++;
    if (n % K == 0)
      break;

    n %= K;
    n = n * 10 + 7;
  }

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:


//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

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

  int ans = 0;

  ll n = 7;
  while (1) {
    ans++;
    if (n % K == 0)
      break;

    n %= K;
    n = n * 10 + 7;
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>

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

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

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

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


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

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

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

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

int main() {
  header();
  solve();
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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


Error: TLE

Fixed submission:

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

#include <bits/stdc++.h>
using namespace std;
#define max1 100005
#define siz 1000005
#define mod 998244353
#define inf 1e18
#define ll long long int
#define debug(x) cout << #x << " " << x << endl
#define jam(x) cout << "Case #" << x << ": "
#define hackercup(x) cout << "Case #" << x << ": "
ll tt;
#define run_time                                                               \\
  cout << "\\nTIME = " << clock() - tt << endl;                                 \\
  tt = clock();
typedef pair<ll, ll> pr;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  tt = clock();
  #endif*/
  ll n;
  cin >> n;
  ll x = 7;
  map<ll, ll> mp;
  bool check = true;
  ll s = 1;
  while (x > 0) {
    if (mp.find(x) != mp.end()) {
      check = false;
      break;
    }
    mp[x]++;
    while (x < n) {
      x = x * 10 + 7;
      s++;
    }
    x = x % n;
  }
  if (check) {
    cout << s << endl;
  } else {
    cout << -1 << endl;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define max1 100005
#define siz 1000005
#define mod 998244353
#define inf 1e18
#define ll long long int
#define debug(x) cout << #x << " " << x << endl
#define jam(x) cout << "Case #" << x << ": "
#define hackercup(x) cout << "Case #" << x << ": "
ll tt;
#define run_time                                                               \\
  cout << "\\nTIME = " << clock() - tt << endl;                                 \\
  tt = clock();
typedef pair<ll, ll> pr;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  /*#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  tt = clock();
  #endif*/
  ll n;
  cin >> n;
  ll x = 7;
  map<ll, ll> mp;
  bool check = true;
  ll s = 1;
  while (x > 0) {
    if (mp[x]) {
      check = false;
      break;
    }
    while (x < n) {
      x = x * 10 + 7;
      s++;
    }
    x = x % n;
  }
  if (check) {
    cout << s << endl;
  } else {
    cout << -1 << endl;
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int x = 7;
  int ans = 1;
  while (true) {
    if (x % k == 0) {
      cout << ans << endl;
      break;
    }
    x *= 10;
    x += 7;
    ans++;
    x %= k;
    if (ans > 1000001) {
      cout << -1 << endl;
      break;
    }
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int k;
  cin >> k;
  if (k % 2 == 0 || k % 5 == 0) {
    cout << -1 << endl;
    return 0;
  }
  int x = 7;
  int ans = 1;
  while (x % k != 0) {
    if (x % k == 0) {
      cout << ans << endl;
      return 0;
    }
    x *= 10;
    x += 7;
    ans++;
  }

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

// Atcoder beginner round 174 C - Repsept

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int K;
  ll a = 7;
  cin >> K;
  if (K % 2 == 0 || K % 10 == 5)
    cout << "-1";
  for (ll x = 1; x <= K; x++) {
    if (a % K == 0) {
      cout << x;
      break;
    }
    a = (a * 10 + 7) % K;
  }
  return 0;
}

Error: TLE

Fixed submission:

// Atcoder beginner round 174 C - Repsept

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int K, cnt = 1;
  int a = 7;
  cin >> K;
  if (K % 2 == 0 || K % 10 == 5)
    cout << "-1";
  while (1) {
    if (a % K == 0) {
      cout << cnt;
      break;
    }
    a = (a * 10 + 7) % K;
    cnt++;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

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

Error: TLE

Fixed submission:

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

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

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

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

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

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

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

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

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

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


Error: TLE

Fixed submission:

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

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

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

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

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

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;
  if (k % 7 == 0) {
    k = k / 7;
  }
  if (k % 2 == 0) {
    cout << -1 << endl;
  } else {
    int a = 1 % k;
    int l = 1;
    while (a > 0) {
      a = (10 * a + 1) % k;
      l++;
    }
    cout << l << endl;
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int K;
  cin >> K;
  int i;
  vector<int> modK(1000010);
  modK.at(0) = 0;

  for (i = 1; i <= K; i++) {
    modK.at(i) = (modK.at(i - 1) * 10 + 7) % K;
  }

  for (i = 1; i <= K; i++) {
    if (modK.at(i) == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  ll k;
  cin >> k;
  ll nums = 7;
  ll index = 1;
  while (nums % k != 0) {
    nums = nums * 10 + 7;
    index++;
  }
  cout << index << "\\n";
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int k, ans = 0, num = 0;
  cin >> k;

  vector<int> v(k, 0);

  do {
    num = num * 10 + 7;
    num = num % k;
    ans++;

    if (v[num]) {
      cout << -1 << "\\n";
      return 0;
    } else
      v[num] = 1;
  } while (num);

  cout << ans << "\\n";
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {

  int k, first = -1;
  cin >> k;

  if (!(k % 2))
    cout << -1 << "\\n";

  else {

    for (int i = 1; i < 10; ++i) {
      if ((i * k) % 10 == 7)
        first = i;
    }

    if (first == -1) {
      cout << -1 << "\\n";
      return 0;
    }

    int close, n;

    n = to_string(first * k).size();
    close = stoi(string(n, '7'));
    while (1) {

      if (!((close - first * k) % k)) {

        cout << n << "\\n";
        return 0;
      } else {

        ++n;
        close = stoi(string(n, '7'));
      }
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  int k;
  cin >> k;
  int d[10000001];
  d[1] = 7 % k;
  for (int i = 2; i <= k; i++) {
    d[i] = (d[i - 1] * 10 + 7) % k;
  }

  for (int i = 1; i <= k; i++) {
    if (d[i] == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Error: 0

Fixed submission:

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

int main(void) {
  int k;
  cin >> k;
  int d[100001];
  d[1] = 7;
  for (int i = 2; i <= k; i++) {
    d[i] = (d[i - 1] * 10 + 7) % k;
  }

  for (int i = 1; i < k; i++) {
    if (d[i] == 0) {
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(), x.end()
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); }

ll k;
ll solve() {
  if (k % 2 == 0)
    return -1;
  ll ans = 1;

  ll cur = 7;
  int i = 0;
  for (; i < 1e8; i++) {
    if (cur % k == 0)
      break;
    ans++;
    cur %= k;
    cur *= 10;
    cur += 7;
  }
  if (i == 1e8)
    return -1;
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> k;

  cout << solve() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(x) x.begin(), x.end()
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); }

ll k;
ll solve() {
  if (k % 2 == 0)
    return -1;
  ll ans = 1;

  ll cur = 7;
  while (true) {
    if (cur % k == 0)
      break;
    ans++;
    cur %= k;
    cur *= 10;
    cur += 7;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> k;

  cout << solve() << endl;
  return 0;
}