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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
// #define _GLIBCXX_DEBUG

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

  unordered_map<int, int> ss;
  int k = 7;
  k %= K;
  int s = 7;
  s %= K;
  ss[s]++;
  int ans = 1;

  while (true) {
    if (s % K == 0) {
      cout << ans << endl;
      return 0;
    }
    k *= 10;
    k %= K;
    s += k;
    s %= K;
    ans++;
    if (ss[s] > 0) {
      cout << -1 << endl;
      return 0;
    } else
      ss[s]++;
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
// #define _GLIBCXX_DEBUG

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

  int k = 7;
  k %= K;
  int s = 7;
  s %= K;
  int ss = s;
  int ans = 1;

  while (true) {
    if (s % K == 0) {
      cout << ans << endl;
      return 0;
    }
    k *= 10;
    k %= K;
    s += k;
    s %= K;
    ans++;
    if (s == ss) {
      cout << -1 << endl;
      return 0;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main() {
  long long int K;
  long long int X = 0;
  int ans = -1;
  cin >> K;
  for (int i = 0; i < 2 * K; i++) {

    X = (10 * X % K + 7) % K;
    X = X % K;
    // cout << X << endl;

    if (X == 0) {
      ans = i + 1;
      break;
    }
  }

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

Error: TLE

Fixed submission:

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

using namespace std;

int main() {
  long long int K;
  long long int X = 0;
  int ans = -1;
  cin >> K;
  for (int i = 0; i < 2 * K; i++) {
    int a = 1;
    for (int j = 0; j < i; j++) {
      a = (a * 10) % K;
    }
    X += (7 * a) % K;
    X = X % K;

    if (X == 0) {
      ans = i + 1;
      break;
    }
  }

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

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

#define pb push_back
#define mp make_pair
typedef long long int ll;

void solve() {
  ll k;
  cin >> k;

  ll total = 0;
  for (int i = 1; i <= 1e8; i++) {
    total = (total * 10 + 7) % k;
    if (total == 0) {
      cout << i;
      return;
    }
  }
  cout << -1;
}

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

#ifndef ONLINE_JUDGE
  freopen("1input.txt", "r", stdin);
  freopen("1output.txt", "w", stdout);
#endif

  int t = 1;
  // cin >> t;

  while (t--) {
    solve();
    cout << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

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

#define pb push_back
#define mp make_pair
typedef long long int ll;

void solve() {
  ll k;
  cin >> k;

  ll total = 0;
  for (int i = 1; i <= 1e9; i++) {
    total = (total * 10 + 7) % k;
    if (total == 0) {
      cout << i;
      return;
    }
  }
  cout << -1;
}

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

#ifndef ONLINE_JUDGE
  freopen("1input.txt", "r", stdin);
  freopen("1output.txt", "w", stdout);
#endif

  int t = 1;
  // cin >> t;

  while (t--) {
    solve();
    cout << "\\n";
  }

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

/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
// codeforces
#include <bits/stdc++.h>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll *A, ll n) {
  for (ll K = 0; K < n; K++) {
    cin >> A[K];
  }
}
ll modInverse(ll a, ll b) {
  return 1 < a ? b - modInverse(b % a, a) * b / a : 1;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b) {
  return sqrt((x - a) * (x - a) + (y - b) * (y - b));
}
void debug(ll *a, ll n) {
  for (ll k = 0; k < n; k++) {
    cerr << a[k] << " ";
  }
  cout << "\\n";
}
#define PI 3.14159265358979323846
#define FF first
#define SS second

int main() {
  FASTIO;
  ll n;
  cin >> n;
  ll sum = 7 % n;
  ll len = 1;
  if (n % 2 == 0)
    return cout << -1 << endl, 0;
  while (sum % n && len < 10000000) {
    sum = (sum * 10) % n;
    sum += 7;
    sum %= n;
    len++;
  }
  if (len >= 10000000)
    return cout << -1 << endl, 0;
  cout << len << endl;
  return 0;
}

Error: TLE

Fixed submission:

/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
// codeforces
#include <bits/stdc++.h>
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll *A, ll n) {
  for (ll K = 0; K < n; K++) {
    cin >> A[K];
  }
}
ll modInverse(ll a, ll b) {
  return 1 < a ? b - modInverse(b % a, a) * b / a : 1;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b) {
  return sqrt((x - a) * (x - a) + (y - b) * (y - b));
}
void debug(ll *a, ll n) {
  for (ll k = 0; k < n; k++) {
    cerr << a[k] << " ";
  }
  cout << "\\n";
}
#define PI 3.14159265358979323846
#define FF first
#define SS second

int main() {
  FASTIO;
  ll n;
  cin >> n;
  ll sum = 7 % n;
  ll len = 1;
  if (n % 2 == 0)
    return cout << -1 << endl, 0;
  while (sum % n) {
    sum = (sum * 10) % n;
    sum += 7;
    sum %= n;
    len++;
  }
  cout << len << 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++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

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

  ll n = 1;
  ll S = 7 % K;
  ll d = 7 % K;

  auto start = clock();

  while (S % K != 0) {
    n++;
    d = (d * 10) % K;
    S = (S + d) % K;

    if (((double)clock() - (double)start) / (double)CLOCKS_PER_SEC >= 1.9) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << n << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

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

  ll n = 1;
  ll S = 7 % K;
  ll d = 7 % K;

  auto start = clock();

  while (S % K != 0) {
    n++;
    d = (d * 10) % K;
    S = (S + d) % K;

    if (((double)clock() - (double)start) / (double)CLOCKS_PER_SEC >= 1.99) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << n << endl;

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

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

#define ll long long

const int N = 1e6 + 4;

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

  ll int k;

  cin >> k;

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

  ll int cur = 7 % k;
  ll int ans = 1;

  while (cur != 0) {
    cur = cur * 10 + 7;
    //		cout << "total is " << cur << "\\n";
    cur %= k;
    //		cout << "after module is " << cur << "\\n";
    ans++;
  }

  cout << ans << "\\n";

  return 0;
}


Error: TLE

Fixed submission:

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

#define ll long long

const int N = 1e6 + 4;

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

  ll int k;

  cin >> k;

  if ((k % 2) == 0 || (k % 5) == 0)
    cout << "-1\\n";

  ll int cur = 7 % k;
  ll int ans = 1;

  while (cur != 0) {
    cur = cur * 10 + 7;
    //		cout << "total is " << cur << "\\n";
    cur %= k;
    //		cout << "after module is " << cur << "\\n";
    ans++;
  }

  cout << ans << "\\n";

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define endl "\\n"
#define inf 2000000000
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
ll mod = 1e9 + 7;

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

      ll n,
      k;
  cin >> n;

  if (n % 2 == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll x = 0;
  ll count = 0;
  while (count <= 1e6) {
    x = (x * 10 + 7) % n;

    if (x == 0) {
      cout << count + 1 << endl;
      return 0;
    }
    count += 1;
  }
  cout << -1;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define endl "\\n"
#define inf 2000000000
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);                                                               \\
  cout.tie(NULL);
ll mod = 1e9 + 7;

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

      ll n,
      k;
  cin >> n;

  if (n % 2 == 0) {
    cout << -1 << endl;
  }
  ll x = 0;
  ll count = 0;
  while (1) {
    x = (x * 10 + 7) % n;

    if (x == 0) {
      cout << count + 1 << endl;
      return 0;
    }
    count += 1;
  }

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

#include <bits/stdc++.h>
/*...
  ...
  author
  @
  Aman Kothari
  .....
  .....*/
using namespace std;
#define ll unsigned long long

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

  ll n;
  cin >> n;
  bool ans = true;
  ll seven = 7, count = -1;
  if (n % 2 == 0 || n % 5 == 0) {
    cout << "-1"
         << "\\n";
  } else {
    ll i = 10;
    while (ans) {
      if (seven % n == 0) {
        count++;
        ans = false;
        break;
      } else {
        count++;
        seven = (seven * i) + 7;
        seven = seven % n;
      }
    }
    cout << ((count + 1)) << "\\n";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
/*...
  ...
  author
  @
  Aman Kothari
  .....
  .....*/
using namespace std;
#define ll long long

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

  ll n;
  cin >> n;
  bool ans = true;
  ll seven = 7, count = -1;
  if (n % 2 == 0) {
    cout << "-1"
         << "\\n";
  } else {
    ll i = 10;
    while (ans) {
      if (seven % n == 0) {
        count++;
        ans = false;
        break;
      } else {
        count++;
        // cout<<seven%n<<"\\n";
        seven = (seven * i) + 7;
        seven = seven % n;
        // i=i*i;
      }
    }
    cout << (count + 1) << "\\n";
  }

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


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const int INF = 1001001001;

int main() {

  int k;
  cin >> k;

  int x = 7 % k;
  set<int> s;
  int ans = 1;
  while (s.count(x) == 0) {
    s.insert(x);
    if (x == 0) {
      cout << ans << endl;
      return 0;
    }
    ans++;
    x = x * 10 + 7;
    x = x % k;
  }

  cout << -1 << endl;

  return 0;
}

Error: 0

Fixed submission:


#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
const int INF = 1001001001;

int main() {

  int k;
  cin >> k;

  string s = "7";
  int ans = 1;
  set<int> SET;
  while (1) {
    int tmp = stoi(s);
    if (tmp % k == 0) {
      cout << ans << endl;
      break;
    }
    if (SET.find(tmp % k) != SET.end()) {
      cout << -1 << endl;
      break;
    }

    SET.insert(tmp % k);
    ans++;
    s += "7";
    // cout << s<< 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 n = 1;
  int S = 7;
  if ((K % 2 == 0) || (K % 5 == 0)) {
    cout << "-1" << endl;
    return 0;
  }
  while (S != 0) {
    if (S >= K)
      S -= K;
    else {
      S = S * 10 + 7;
      n++;
      if (n > K) {
        // cout << "-1" << endl;
        // return 0;
      }
    }
  }
  cout << n << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

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

#include <iostream>
#include <math.h>
using namespace std;
int main() {
  long n = 1, k, num = 7;
  cin >> k;
  while (num % k != 0) {
    long a = num / k;
    num = num - a * k;
    num = num * 10 + 7;
    n++;
    if (n > 10000000) {
      n = -1;
      break;
    }
  }
  cout << n;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int n = 1, k, num = 7;
  cin >> k;
  while (num % k != 0) {
    int a = num / k;
    num = num - a * k;
    num = num * 10 + 7;
    n++;
    if (num > pow(2, 32)) {
      n = -1;
      break;
    }
  }
  cout << n;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  long long i = 0;
  long long val = 0;
  long long first = -1;

  while (true) {
    i++;
    val = val * 10 + 7;
    long long rem = val % k;
    if (rem == 0) {
      break;
    }
    if (first == rem) {
      i = -1;
      break;
    }
    if (i > 2 * k) {
      i = -1;
      break;
    }
    val = rem;
  }
  cout << i << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

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

  long long i = 0;
  long long val = 0;
  long long first = -1;

  while (true) {
    i++;
    val = val * 10 + 7;
    long long rem = val % k;
    if (rem == 0) {
      break;
    }
    if (first == rem) {
      i = -1;
      break;
    }
    if (first < 0) {
      first = rem;
    }
    val = rem;
  }
  cout << i << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (1 ? 1e9 + 7 : 998244353);
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
ll a, b, c, d, e, f, n, T;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> a;
  if (a % 2 == 0 || a % 5 == 0)
    cout << -1 << endl;
  else {
    b = 7;
    c = 1;
    while (b % a != 0) {
      b %= a;
      b *= 10;
      b += 7;
      c++;
    }
    cout << c << endl;
  }
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (1 ? 1e9 + 7 : 998244353);
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
ll a, b, c, d, e, f, n, T;

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

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

int main() {
  ll n;
  cin >> n;
  ll tmp = 7;
  //    ll ans = 0;

  for (ll i = 1; i < 100000000; ++i) {
    if (tmp % n == 0) {
      cout << i << endl;
      return 0;
    }
    tmp *= 10;
    tmp += 7;
    tmp %= n;
  }
  cout << -1 << endl;
  //    cout<<ans<<endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  ll n;
  cin >> n;
  ll tmp = 7;
  //    ll ans = 0;

  for (ll i = 1; i < 1000000000; ++i) {
    if (tmp % n == 0) {
      cout << i << endl;
      return 0;
    }
    tmp *= 10;
    tmp += 7;
    tmp %= n;
  }
  cout << -1 << endl;
  //    cout<<ans<<endl;
  return 0;
}
Problem p02596 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << "\\n"
typedef long long ll;

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

  int n = 7 % k;
  ll ans = -1;
  for (int i = 1; i <= 10e6; i++) {
    if (n == 0) {
      ans = i;
      break;
    }
    n = (n * 10 + 7) % k;
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int a[10001];
int main() {
  ll k;
  cin >> 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) {
      cout << i << endl;
      return 0;
    }
  }

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(), v.end()

int main() {
  int k;
  cin >> k;
  int a = 0;
  int count = 0;
  if (k % 2 == 0 || k % 5 == 0) {
    count = -1;
  } else {
    while (1) {
      count++;
      a = (a * 10 + 7) % k;
      if (a == 0) {
        break;
      }
      if (count == k) {
        count = -1;
      }
    }
  }
  cout << count << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(), v.end()

int main() {
  int k;
  cin >> k;
  ll a = 0;
  int count = 0;
  if (k % 2 == 0 || k % 5 == 0) {
    count = -1;
  } else {
    while (1) {
      count++;
      a *= 10;
      a += 7;
      if (a % k == 0) {
        break;
      }
      if (count == 1000000) {
        count = -1;
      }
    }
  }
  cout << count << endl;
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

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

typedef vector<int> vi;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define pmod 1000000007
#define INF 1000000000000000000
#define pi atan(1) * 4
#define modi 1000000

void solve() {

  ll k;
  cin >> k;

  bitset<2000000> alfa;

  ll res = 7 % k;

  alfa[res] = 1;
  ll counter = 1;

  bool can = true;

  while (res != 0) {

    res = (res * 10 + 7) % k;

    if (alfa[res]) {
      can = false;
      res = 0;
    }

    alfa[res] = 1;

    counter++;
  }

  if (can)
    cout << counter << endl;

  if (!can)
    cout << -1 << endl;
}

int main() {

  ifstream fin("text.in");
  ofstream fout("text.out");

  ll t = 1;

  while (t--)
    solve();

  return 0;
}

Error: TLE

Fixed submission:

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

typedef vector<int> vi;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define pmod 1000000007
#define INF 1000000000000000000
#define pi atan(1) * 4
#define modi 1000000

void solve() {

  ll k;
  cin >> k;

  bitset<2000000> alfa;

  ll res = 7 % k;

  alfa[res] = 1;

  ll counter = 1;
  bool can = true;

  while (res != 0) {

    res = (res * 10 + 7) % k;

    if (alfa[res]) {
      can = false;
      res = 0;
    }

    counter++;
  }

  if (can)
    cout << counter << endl;

  if (!can)
    cout << -1 << endl;
}

int main() {

  ifstream fin("text.in");
  ofstream fout("text.out");

  ll t = 1;

  while (t--)
    solve();

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

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

int main() {
  int K;
  int64_t iSeven = 0;
  cin >> K;

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

  for (int i = 1; i < 1000010; i++) {
    iSeven = (iSeven * 10 + 7) % K;
    if (iSeven == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int K, a = 0;
  int64_t iSeven = 0;
  cin >> K;

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

  while (true) {
    iSeven = (iSeven * 10 + 7) % K;
    a++;
    if (iSeven == 0) {
      cout << a << endl;
      return 0;
    }
  }
}
Problem p02596 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define F first
#define S second
using namespace std;

int main() {
  ll t, i, j, k, ans, n;

  // cin>>t;
  t = 1;
  while (t--) {
    ll term = 7, pos = 1;
    cin >> k;
    i = 0;

    while (i <= 2 * k && term % k) {
      term = (term * 10 % k + 7 % k) % k;
      pos++;
      i++;
    }

    if (term % k == 0)
      cout << pos;
    else
      cout << "-1";
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define F first
#define S second
using namespace std;

int main() {
  ll t, i, j, k, ans, n;

  // cin>>t;
  t = 1;
  while (t--) {
    ll term = 7, pos = 1;
    cin >> k;
    i = 0;

    while (i <= k * k && term % k) {
      term = (term * 10 % k + 7 % k) % k;
      pos++;
      i++;
    }

    if (term % k == 0)
      cout << pos;
    else
      cout << "-1";
  }

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define arr(n) array<int, n>
#define INF 1e9
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  ll K;
  cin >> K;
  ll x = 0;
  rep(i, 30000000) {
    x = (x * 10 + 7) % K;
    if (x == 0) {
      cout << (i + 1) << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define arr(n) array<int, n>
#define INF 1e9
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  ll K;
  cin >> K;
  ll x = 0;
  rep(i, 300000000) {
    x = (x * 10 + 7) % K;
    if (x == 0) {
      cout << (i + 1) << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}