problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02596 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll>>
#define fi first
#define se second
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 998244353;
signed main() {
ll k;
cin >> k;
ll ans = -1;
vector<ll> a(k + 1);
a[0] = 7 % k;
rep(i, k + 1) {
if (a[i] % k == 0) {
ans = i + 1;
break;
}
if (i < k + 1)
a[i + 1] = (a[i] * 10 + 7) % k;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll>>
#define fi first
#define se second
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 998244353;
signed main() {
ll k;
cin >> k;
ll ans = -1;
vector<ll> a(k + 1);
a[0] = 7 % k;
rep(i, k + 1) {
if (a[i] % k == 0) {
ans = i + 1;
break;
}
if (i < k)
a[i + 1] = (a[i] * 10 + 7) % k;
}
cout << ans << endl;
} | replace | 30 | 31 | 30 | 31 | 0 | |
p02596 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
typedef long long ll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
const int INF = 1e9;
#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
int guki(int a) {
if (a % 2 == 0)
return 0;
else
return 1;
}
int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
return (gcd(b, a % b));
}
}
int lcm(int a, int b) {
int x = gcd(a, b);
return (a * b / x);
}
using namespace std;
// now
struct UnionFind {
vector<int> d;
UnionFind(int n = 0) : d(n, -1) {}
int Find(int x) { // 根の番号を探す
if (d[x] < 0)
return x;
return d[x] = Find(d[x]);
}
bool unite(int x, int y) {
x = Find(x);
y = Find(y);
if (x == y)
return false;
if (d[x] < d[y]) {
swap(x, y);
}
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x, int y) { return Find(x) == Find(y); }
int size(int x) { return (-d[Find(x)]); }
};
ll nCr(ll n, ll r) {
ll ans = 1;
for (ll i = n; i > n - r; i--) {
ans *= i;
}
for (ll i = 1; i <= r; i++) {
ans /= i;
}
return ans;
}
int nPr(int n, int r) {
int ans = 1;
for (int i = n; i > n - r; i--) {
ans *= i;
}
return ans;
}
ll modd = 1e9 + 7;
ll wa(ll n, ll mi, ll ma) {
ll ans = n * (mi + ma) / 2;
return ans;
}
ll kw(ll k, ll n) {
ll ans = 0;
ll mi, ma;
mi = wa(k, 0, k - 1);
ma = wa(k, n - k + 1, n);
return (ma - mi + 1) % modd;
}
int main() {
int a[100000001];
int 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;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
typedef long long ll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
const int INF = 1e9;
#define FOR(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
int guki(int a) {
if (a % 2 == 0)
return 0;
else
return 1;
}
int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
return (gcd(b, a % b));
}
}
int lcm(int a, int b) {
int x = gcd(a, b);
return (a * b / x);
}
using namespace std;
// now
struct UnionFind {
vector<int> d;
UnionFind(int n = 0) : d(n, -1) {}
int Find(int x) { // 根の番号を探す
if (d[x] < 0)
return x;
return d[x] = Find(d[x]);
}
bool unite(int x, int y) {
x = Find(x);
y = Find(y);
if (x == y)
return false;
if (d[x] < d[y]) {
swap(x, y);
}
d[x] += d[y];
d[y] = x;
return true;
}
bool same(int x, int y) { return Find(x) == Find(y); }
int size(int x) { return (-d[Find(x)]); }
};
ll nCr(ll n, ll r) {
ll ans = 1;
for (ll i = n; i > n - r; i--) {
ans *= i;
}
for (ll i = 1; i <= r; i++) {
ans /= i;
}
return ans;
}
int nPr(int n, int r) {
int ans = 1;
for (int i = n; i > n - r; i--) {
ans *= i;
}
return ans;
}
ll modd = 1e9 + 7;
ll wa(ll n, ll mi, ll ma) {
ll ans = n * (mi + ma) / 2;
return ans;
}
ll kw(ll k, ll n) {
ll ans = 0;
ll mi, ma;
mi = wa(k, 0, k - 1);
ma = wa(k, n - k + 1, n);
return (ma - mi + 1) % modd;
}
int main() {
int a[1000001];
int 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;
}
| replace | 103 | 104 | 103 | 104 | -11 | |
p02596 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
long long int k;
cin >> k;
if (k % 2 == 0) {
cout << -1 << endl;
} else {
long long int now = 7;
long long int count = 1;
while (true) {
if (now % k == 0) {
cout << count << endl;
break;
} else {
now *= 10;
now += 7;
now %= k;
count++;
}
}
}
} | #include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
long long int k;
cin >> k;
if (k % 2 == 0 || k % 5 == 0) {
cout << -1 << endl;
} else {
long long int now = 7;
long long int count = 1;
while (true) {
if (now % k == 0) {
cout << count << endl;
break;
} else {
now *= 10;
now += 7;
now %= k;
count++;
}
}
}
} | replace | 14 | 15 | 14 | 15 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template <class T> void printvec(const vector<T> &v) {
for (auto x : v) {
cout << x << " ";
}
cout << endl;
}
template <class T> void printtree(const vector<vector<T>> &tree) {
for (long long i = 0; i < tree.size(); ++i) {
cout << i + 1 << ": ";
printvec(tree[i]);
}
}
template <class T, class U> void printmap(const map<T, U> &mp) {
for (auto x : mp) {
cout << x.first << "=>" << x.second << endl;
}
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll INF = 1e9;
ll MOD;
// Mod int
// cf. https://www.youtube.com/watch?v=1Z6ofKN03_Y
struct mint {
ll x;
mint(ll x = 0) : x((x + MOD) % MOD) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x %= MOD;
return *this;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t) {
return 1;
}
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// ref. https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
mint invWithGcd() const {
ll a = x, b = MOD, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= MOD;
if (u < 0) {
u += MOD;
}
return mint(u);
}
// for prime mod
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// int main(int argc, char** argv) {
// // int p;
// // cin >> p;
//
// MOD = 13;
// mint p(10);
// cout << (p + 15).x << endl; // 12 (25 % 13)
// cout << (p - 15).x << endl; // 8 (-5 % 13)
// cout << (p * 2).x << endl; // 7 (20 % 13)
// cout << (p.pow(3)).x << endl; // 12 (1000 % 13)
// cout << (p / 3).x << endl; // 12 (12 * 3 = 10 (36 % 13))
// cout << p * mint(3).invWithGcd().x << endl; // 12 (12 * 3 = 10 (36 % 13))
//
// mint p2(-3);
// cout << p2.x << endl; // 10 (-3 % 13)
// }
int main(int argc, char **argv) {
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
// cout << setprecision(10) << fixed;
ll k;
cin >> k;
MOD = k;
if (k % 2 == 0) { // even
cout << -1 << endl;
return 0;
}
mint now = 0;
rep(i, k * 10) {
now += mint(10).pow(i) * 7;
if (now.x == 0) {
cout << i + 1 << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <unordered_map>
#include <vector>
using namespace std;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template <class T> void printvec(const vector<T> &v) {
for (auto x : v) {
cout << x << " ";
}
cout << endl;
}
template <class T> void printtree(const vector<vector<T>> &tree) {
for (long long i = 0; i < tree.size(); ++i) {
cout << i + 1 << ": ";
printvec(tree[i]);
}
}
template <class T, class U> void printmap(const map<T, U> &mp) {
for (auto x : mp) {
cout << x.first << "=>" << x.second << endl;
}
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll INF = 1e9;
ll MOD;
// Mod int
// cf. https://www.youtube.com/watch?v=1Z6ofKN03_Y
struct mint {
ll x;
mint(ll x = 0) : x((x + MOD) % MOD) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x %= MOD;
return *this;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t) {
return 1;
}
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// ref. https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
mint invWithGcd() const {
ll a = x, b = MOD, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= MOD;
if (u < 0) {
u += MOD;
}
return mint(u);
}
// for prime mod
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// int main(int argc, char** argv) {
// // int p;
// // cin >> p;
//
// MOD = 13;
// mint p(10);
// cout << (p + 15).x << endl; // 12 (25 % 13)
// cout << (p - 15).x << endl; // 8 (-5 % 13)
// cout << (p * 2).x << endl; // 7 (20 % 13)
// cout << (p.pow(3)).x << endl; // 12 (1000 % 13)
// cout << (p / 3).x << endl; // 12 (12 * 3 = 10 (36 % 13))
// cout << p * mint(3).invWithGcd().x << endl; // 12 (12 * 3 = 10 (36 % 13))
//
// mint p2(-3);
// cout << p2.x << endl; // 10 (-3 % 13)
// }
int main(int argc, char **argv) {
cin.tie(NULL);
cout.tie(NULL);
ios_base::sync_with_stdio(false);
// cout << setprecision(10) << fixed;
ll k;
cin >> k;
MOD = k;
if (k % 2 == 0) { // even
cout << -1 << endl;
return 0;
}
mint now = 0;
rep(i, k + 5) {
now += mint(10).pow(i) * 7;
if (now.x == 0) {
cout << i + 1 << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
| replace | 173 | 174 | 173 | 174 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define MM(arr, x) memset(arr, x, sizeof(arr))
#define INF 0x3f3f3f3f
#define Maxn 1e5 + 10;
using namespace std;
int main() {
ios::sync_with_stdio(0);
ll ans = 0, k, now = 0;
cin >> k;
while (ans <= 999999999) {
ans++;
now = (now * 10 + 7) % k;
if (now == 0) {
cout << ans;
return 0;
}
}
cout << -1;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define MM(arr, x) memset(arr, x, sizeof(arr))
#define INF 0x3f3f3f3f
#define Maxn 1e5 + 10;
using namespace std;
int main() {
ios::sync_with_stdio(0);
ll ans = 0, k, now = 0;
cin >> k;
while (ans <= 99999999) {
ans++;
now = (now * 10 + 7) % k;
if (now == 0) {
cout << ans;
return 0;
}
}
cout << -1;
return 0;
} | replace | 10 | 11 | 10 | 11 | TLE | |
p02596 | C++ | Time Limit Exceeded | /*
このコード、と~おれ!
Be accepted!
∧_∧
(。・ω・。)つ━☆・*。
⊂ ノ ・゜+.
しーJ °。+ *´¨)
.· ´¸.·*´¨) ¸.·*¨)
(¸.·´ (¸.·'* ☆
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
////多倍長整数, cpp_intで宣言
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #pragma gcc target ("avx2")
// #pragma gcc optimization ("Ofast")
// #pragma gcc optimization ("unroll-loops")
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) // 少数出力
#define printLdb(a) printf("%.50Lf\n", a) // 少数出力
#define printdbd(a) printf("%.16lf\n", a) // 少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) // string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg) / 360.0L) * 2.0L * PI)
#define rad_to_deg(rad) (((rad) / 2.0L / PI) * 360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) \
(abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()
using ll = long long;
using ull = unsigned long long;
constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);
using namespace std;
void scans(string &str) {
char c;
str = "";
scanf("%c", &c);
if (c == '\n')
scanf("%c", &c);
while (c != '\n' && c != -1 && c != ' ') {
str += c;
scanf("%c", &c);
}
}
void scanc(char &str) {
char c;
scanf("%c", &c);
if (c == -1)
return;
while (c == '\n') {
scanf("%c", &c);
}
str = c;
}
double acot(double x) { return PI / 2 - atan(x); }
ll LSB(ll n) { return (n & (-n)); }
template <typename T> T chmin(T &a, const T &b) {
if (a > b)
a = b;
return a;
}
template <typename T> T chmax(T &a, const T &b) {
if (a < b)
a = b;
return a;
}
/*-----------------------------------------ここからコード-----------------------------------------*/
int main() {
int k;
scanf("%d", &k);
if (k % 2 == 0) {
puts("-1");
return 0;
} else if (k % 7 == 0) {
k /= 7;
}
ll sum = 1, r = 1;
ll ans = 1;
while (sum % k) {
r *= 10;
r %= k;
sum += r;
sum %= k;
++ans;
if (ans >= 1e8) {
ans = -1;
break;
}
}
printf("%lld\n", ans);
Please AC;
}
| /*
このコード、と~おれ!
Be accepted!
∧_∧
(。・ω・。)つ━☆・*。
⊂ ノ ・゜+.
しーJ °。+ *´¨)
.· ´¸.·*´¨) ¸.·*¨)
(¸.·´ (¸.·'* ☆
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
////多倍長整数, cpp_intで宣言
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// #pragma gcc target ("avx2")
// #pragma gcc optimization ("Ofast")
// #pragma gcc optimization ("unroll-loops")
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) // 少数出力
#define printLdb(a) printf("%.50Lf\n", a) // 少数出力
#define printdbd(a) printf("%.16lf\n", a) // 少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) // string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg) / 360.0L) * 2.0L * PI)
#define rad_to_deg(rad) (((rad) / 2.0L / PI) * 360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) \
(abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()
using ll = long long;
using ull = unsigned long long;
constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);
using namespace std;
void scans(string &str) {
char c;
str = "";
scanf("%c", &c);
if (c == '\n')
scanf("%c", &c);
while (c != '\n' && c != -1 && c != ' ') {
str += c;
scanf("%c", &c);
}
}
void scanc(char &str) {
char c;
scanf("%c", &c);
if (c == -1)
return;
while (c == '\n') {
scanf("%c", &c);
}
str = c;
}
double acot(double x) { return PI / 2 - atan(x); }
ll LSB(ll n) { return (n & (-n)); }
template <typename T> T chmin(T &a, const T &b) {
if (a > b)
a = b;
return a;
}
template <typename T> T chmax(T &a, const T &b) {
if (a < b)
a = b;
return a;
}
/*-----------------------------------------ここからコード-----------------------------------------*/
int main() {
int k;
scanf("%d", &k);
if (k % 2 == 0 or k % 5 == 0) {
puts("-1");
return 0;
} else if (k % 7 == 0) {
k /= 7;
}
ll sum = 1, r = 1;
ll ans = 1;
while (sum % k) {
r *= 10;
r %= k;
sum += r;
sum %= k;
++ans;
if (ans >= 1e8) {
ans = -1;
break;
}
}
printf("%lld\n", ans);
Please AC;
}
| replace | 116 | 117 | 116 | 117 | TLE | |
p02596 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define rep(i, a, b) for (long long i = a; i < b; i += 1)
#define repr(i, a, b) for (long long i = a; i <= b; i += 1)
#define vec vector<ll>
#define map map<char, int>
#define repa(p, A) for (auto p : A)
#define pb push_back
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
const double PI = acos(-1);
const ll INF = 1000000;
using namespace std;
int main() {
ll K;
cin >> K;
vec A(K);
A[0] = 7;
rep(i, 0, K) { A[i + 1] = (A[i] * 10 + 7) % K; }
rep(i, 0, K) {
if (A[i] % K == 0) {
cout << i + 1 << endl;
return 0;
}
}
cout << "-1" << endl;
}
| #include <bits/stdc++.h>
#define ll long long
#define rep(i, a, b) for (long long i = a; i < b; i += 1)
#define repr(i, a, b) for (long long i = a; i <= b; i += 1)
#define vec vector<ll>
#define map map<char, int>
#define repa(p, A) for (auto p : A)
#define pb push_back
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
const double PI = acos(-1);
const ll INF = 1000000;
using namespace std;
int main() {
ll K;
cin >> K;
vec A(K);
A[0] = 7;
rep(i, 0, K - 1) { A[i + 1] = (A[i] * 10 + 7) % K; }
rep(i, 0, K) {
if (A[i] % K == 0) {
cout << i + 1 << endl;
return 0;
}
}
cout << "-1" << endl;
}
| replace | 19 | 20 | 19 | 20 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p02596 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, d, cnt = 1;
set<ll> s;
cin >> n;
ll aux = 1;
if (n % 7 == 0)
n %= 7;
while (1) {
if (s.find(aux) != s.end()) {
cout << "-1";
return 0;
}
if (aux % n == 0)
break;
s.insert(aux);
cnt++;
aux %= n;
aux = aux * 10 + 1;
}
cout << cnt;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, d, cnt = 1;
set<ll> s;
cin >> n;
ll aux = 1;
if (n % 7 == 0)
n /= 7;
while (1) {
if (s.find(aux) != s.end()) {
cout << "-1";
return 0;
}
if (aux % n == 0)
break;
s.insert(aux);
cnt++;
aux %= n;
aux = aux * 10 + 1;
}
cout << cnt;
} | replace | 14 | 15 | 14 | 16 | 0 | |
p02596 | C++ | Time Limit Exceeded | #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
int main() {
long long k;
cin >> k;
// 偶数は排除
if (k % 2 == 0 || k % 5 == 0) {
cout << -1 << endl;
return 0;
}
long long count = 0;
long long i = 1;
long long number = 7;
while (1) {
if (number % k == 0) {
count = i;
break;
}
number = number * 10 + 7;
i++;
}
cout << count << endl;
return 0;
} | #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
using namespace std;
int main() {
long long k;
cin >> k;
// 偶数は排除
if (k % 2 == 0 || k % 5 == 0) {
cout << -1 << endl;
return 0;
}
long long count = 0;
long long i = 1;
long long number = 7;
while (1) {
if (number % k == 0) {
count = i;
break;
}
number = (number % k) * 10 + 7;
i++;
}
cout << count << endl;
return 0;
} | replace | 31 | 32 | 31 | 32 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int k;
scanf("%d", &k);
if (k % 2 == 0) {
printf("-1");
} else {
ll cnt = 0, sum = 0;
while (true) {
cnt++;
sum = sum * 10 + 7;
if (sum % k == 0) {
break;
} else
sum %= k;
}
printf("%lld", cnt);
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int k;
scanf("%d", &k);
if (k % 2 == 0 || k % 5 == 0) {
printf("-1");
} else {
ll cnt = 0, sum = 0;
while (true) {
cnt++;
sum = sum * 10 + 7;
if (sum % k == 0) {
break;
} else
sum %= k;
}
printf("%lld", cnt);
}
return 0;
}
| replace | 7 | 8 | 7 | 8 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define all(x) (x).begin(), (x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int mod = 1e9 + 7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
void solve() {
ll k;
cin >> k;
if (k % 2 == 0)
cout << -1 << '\n';
else {
int cnt = 1;
ll val = 7;
while (val % k) {
val = val * 10 % k;
val = (val + 7) % k;
cnt++;
}
cout << cnt << '\n';
}
}
int main() {
IOS int t = 1;
// cin>>t;
while (t--) {
solve();
}
}
| #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mii map<int, int>
#define mll map<ll, ll>
#define all(x) (x).begin(), (x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int mod = 1e9 + 7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
void solve() {
ll k;
cin >> k;
if (k % 2 == 0 || k % 5 == 0)
cout << -1 << '\n';
else {
int cnt = 1;
ll val = 7;
while (val % k) {
val = val * 10 % k;
val = (val + 7) % k;
cnt++;
}
cout << cnt << '\n';
}
}
int main() {
IOS int t = 1;
// cin>>t;
while (t--) {
solve();
}
}
| replace | 35 | 36 | 35 | 36 | TLE | |
p02596 | C++ | Runtime Error | #include <bits/stdc++.h>
// #pragma GCC optimize ("-O3")
using namespace std;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// const long double PI = 3.14159265358979323846; /* pi */
int main() {
// ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int k;
cin >> k;
vector<bool> visited(k, false);
int val = 0;
int ans = 0;
for (int i = 0; i < 1e6; i++) {
ans++;
val = val * 10 + 7;
int rem = val % k;
if (visited[rem])
break;
visited[rem] = true;
if (rem == 0)
break;
}
if (visited[0])
cout << ans << "\n";
else
cout << -1 << "\n";
return 0;
}
| #include <bits/stdc++.h>
// #pragma GCC optimize ("-O3")
using namespace std;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// const long double PI = 3.14159265358979323846; /* pi */
int main() {
// ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int k;
cin >> k;
vector<bool> visited(k, false);
int val = 0;
int ans = 0;
for (int i = 0; i < 1e6; i++) {
ans++;
val = val * 10 + 7;
val = val % k;
int rem = val % k;
if (visited[rem])
break;
visited[rem] = true;
if (rem == 0)
break;
}
if (visited[0])
cout << ans << "\n";
else
cout << -1 << "\n";
return 0;
}
| insert | 17 | 17 | 17 | 18 | 0 | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
} else {
return false;
}
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
} else {
return false;
}
}
#define ll long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mod (ll)(1e9 + 7)
#define inf (ll)(3e18 + 7)
#define pi (double)acos(-1.0)
#define P pair<int, int>
#define PiP pair<ll, pair<ll, ll>>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
int main() {
ll k;
cin >> k;
if (k % 2 == 0) {
cout << -1 << endl;
return 0;
}
ll now = 7 % k, i = 1;
while (true) {
if (now % k == 0) {
cout << i << endl;
return 0;
}
i++;
now *= 10;
now += 7;
now %= k;
}
} | #include <bits/stdc++.h>
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
} else {
return false;
}
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
} else {
return false;
}
}
#define ll long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, n) for (int i = 1; i <= (n); i++)
#define mod (ll)(1e9 + 7)
#define inf (ll)(3e18 + 7)
#define pi (double)acos(-1.0)
#define P pair<int, int>
#define PiP pair<ll, pair<ll, ll>>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
int main() {
ll k;
cin >> k;
if (k % 2 == 0 || k % 5 == 0) {
cout << -1 << endl;
return 0;
}
ll now = 7 % k, i = 1;
while (true) {
if (now % k == 0) {
cout << i << endl;
return 0;
}
i++;
now *= 10;
now += 7;
now %= k;
}
} | replace | 33 | 34 | 33 | 34 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
int k;
cin >> k;
if (k % 2 == 0) {
cout << -1 << endl;
return 0;
}
int ans = 1;
int cur = 7 % k;
while (cur != 0) {
cur = 10 * cur + 7;
cur %= k;
++ans;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
int k;
cin >> k;
if (k % 2 == 0) {
cout << -1 << endl;
return 0;
}
int ans = 1;
int cur = 7 % k;
while (cur != 0) {
cur = 10 * cur + 7;
cur %= k;
++ans;
if (ans > 100000000) {
ans = -1;
break;
}
}
cout << ans << endl;
}
| insert | 17 | 17 | 17 | 21 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <iostream>
int main() {
unsigned long long N;
std::cin >> N;
unsigned long long amari = 0;
unsigned long long last_amari = 7 % N;
amari += last_amari;
int cnt = 1;
if (N % 2 == 0) {
std::cout << -1 << std::endl;
return 0;
}
while (amari) {
last_amari *= 10;
last_amari %= N;
amari += last_amari;
amari %= N;
cnt++;
}
std::cout << cnt << std::endl;
return 0;
} | #include <iostream>
int main() {
unsigned long long N;
std::cin >> N;
unsigned long long amari = 0;
unsigned long long last_amari = 7 % N;
amari += last_amari;
int cnt = 1;
if (N % 2 == 0 || N % 5 == 0) {
std::cout << -1 << std::endl;
return 0;
}
while (amari) {
last_amari *= 10;
last_amari %= N;
amari += last_amari;
amari %= N;
cnt++;
}
std::cout << cnt << std::endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | TLE | |
p02596 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define reps(i, a, b) for (int i = a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
ll k;
cin >> k;
vector<ll> vec(k + 1, 0);
vec.at(1) = 7 % k;
for (ll i = 2; i <= k + 1; i++) {
if (vec.at(i - 1) == 0) {
cout << i - 1 << endl;
return 0;
}
vec.at(i) = (vec.at(i - 1) * 10 + 7) % k;
}
cout << -1 << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define reps(i, a, b) for (int i = a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
ll k;
cin >> k;
vector<ll> vec(k + 2, 0);
vec.at(1) = 7 % k;
for (ll i = 2; i <= k + 1; i++) {
if (vec.at(i - 1) == 0) {
cout << i - 1 << endl;
return 0;
}
vec.at(i) = (vec.at(i - 1) * 10 + 7) % k;
}
cout << -1 << endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p02596 | C++ | Time Limit Exceeded | // #include"bits/stdc++.h"
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define rep(i, j) FOR(i, 0, j, 1)
#define MP make_pair
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout << "##" << x << "##" << endl
const int INF = (int)2e9 + 9;
const int SIZE = (int)2e5 + 5;
// Brute force answers(BINARY SEARCH) symmetry
// Change perspective
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll k;
cin >> k;
if (k % 2 == 0) {
cout << -1;
} else {
int min1 = 0, temp = k;
while (temp > 0) {
temp /= 10;
min1++;
}
int ans = 0, pref = 0;
ll cnt = 7;
while (1) {
ans++;
pref += cnt;
pref %= k;
if (pref == 0) {
break;
}
cnt = (cnt * 10) % k;
}
cout << ans;
}
} | // #include"bits/stdc++.h"
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i = j; i < k; i += in)
#define rep(i, j) FOR(i, 0, j, 1)
#define MP make_pair
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout << "##" << x << "##" << endl
const int INF = (int)2e9 + 9;
const int SIZE = (int)2e5 + 5;
// Brute force answers(BINARY SEARCH) symmetry
// Change perspective
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll k;
cin >> k;
if (k % 2 == 0) {
cout << -1;
} else {
int min1 = 0, temp = k;
while (temp > 0) {
temp /= 10;
min1++;
}
int ans = 0, pref = 0;
ll cnt = 7;
while (1) {
ans++;
pref += cnt;
pref %= k;
if (pref == 0) {
break;
}
cnt = (cnt * 10) % k;
if (ans >= (int)1e6) {
ans = -1;
break;
}
}
cout << ans;
}
} | insert | 49 | 49 | 49 | 53 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int k;
cin >> k;
ll sum = 1;
int a = 7 % k;
int tmp = a;
bool flg = true;
while (a) {
a = 10 * a + 7;
a %= k;
if (tmp == a) {
flg = false;
break;
}
sum++;
}
if (flg) {
cout << sum << endl;
} else {
cout << -1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int k;
cin >> k;
ll sum = 1;
int a = 7 % k;
int tmp = a;
bool flg = true;
while (a) {
a = 10 * a + 7;
a %= k;
if (sum > k) {
flg = false;
break;
}
sum++;
}
if (flg) {
cout << sum << endl;
} else {
cout << -1 << endl;
}
return 0;
} | replace | 15 | 16 | 15 | 16 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
int L, i = 1;
int ans = -1;
if (K % 7 == 0)
L = 9 * K / 7;
else
L = 9 * K;
if (L % 2 != 0 || L % 5 != 0) {
int m = 10 % L;
if (m == 1)
ans = 1;
else {
do {
m = m * 10 % L;
i++;
} while (m != 1);
ans = i;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
int L, i = 1;
int ans = -1;
if (K % 7 == 0)
L = 9 * K / 7;
else
L = 9 * K;
if (L % 2 != 0 && L % 5 != 0) {
int m = 10 % L;
if (m == 1)
ans = 1;
else {
do {
m = m * 10 % L;
i++;
} while (m != 1);
ans = i;
}
}
cout << ans << endl;
}
| replace | 12 | 13 | 12 | 13 | TLE | |
p02596 | C++ | 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.99) {
cout << -1 << endl;
return 0;
}
}
cout << n << endl;
return 0;
} | #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;
} | replace | 25 | 26 | 25 | 26 | TLE | |
p02596 | C++ | Time Limit Exceeded | // May this submission get accepted
#include <bits/stdc++.h>
// エイリアス
using ll = long signed long;
using ull = long unsigned long;
using ld = long double;
using namespace std;
// AtCoder/Codeforces 用 デバッグ検知
#ifdef ONLINE_JUDGE
constexpr bool DEBUG_MODE = false;
#else
constexpr bool DEBUG_MODE = true;
#endif
// エイリアス (補完・コンパイルが重くなる)
// #include <boost/multiprecision/cpp_int.hpp>
// using mll = boost::multiprecision::cpp_int;
// 汎用マクロ
#define ALLOF(x) (x).begin(), (x).end()
#define REP(i, n) for (long long i = 0, i##_len = (n); i < i##_len; i++)
#define RANGE(i, is, ie) \
for (long long i = (is), i##_end = (ie); i <= i##_end; i++)
#define DSRNG(i, is, ie) \
for (long long i = (is), i##_end = (ie); i >= i##_end; i--)
#define STEP(i, is, ie, step) \
for (long long i = (is), i##_end = (ie), i##_step = (step); i <= i##_end; \
i += i##_step)
#define UNIQUE(v) \
do { \
sort((v).begin(), (v).end()); \
(v).erase(unique((v).begin(), (v).end()), (v).end()); \
} while (false)
#define FOREACH(i, q) for (auto &i : q)
template <typename T, typename U> bool chmax(T &a, const U b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T, typename U> bool chmin(T &a, const U b) {
if (a > b) {
a = b;
return true;
}
return false;
}
constexpr int INF = numeric_limits<int>::max();
constexpr long long LINF = numeric_limits<long long>::max();
constexpr long double EPS = 1e-10L;
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define IIF(q, t, f) ((q) ? (t) : (f))
#define DUMP(q) DUMP_FUNC(q, #q, __FILE__, __LINE__)
template <typename T> void DUMP_PROC(T x) {
if (is_integral<T>() || is_floating_point<T>())
cerr << "\e[32m" << x << "\e[m";
else
cerr << x;
}
template <> void DUMP_PROC<char>(char x) {
cerr << "\e[36m\'" << x << "\'\e[m";
}
template <> void DUMP_PROC<string>(string x) {
cerr << "\e[33m\"" << x << "\"\e[m";
}
template <typename T, typename U> void DUMP_PROC(pair<T, U> x) {
cerr << "{";
DUMP_PROC(x.first);
cerr << ", ";
DUMP_PROC(x.second);
cerr << "}";
}
template <typename... T, typename U, U... Seq>
void DUMP_PROC(tuple<T...> &x, integer_sequence<U, Seq...>) {
(void)(int[]){(cerr << ((const char *[]){"", ", "})[!!Seq]
<< (DUMP_PROC(get<Seq>(x)), ""),
0)...};
}
template <typename... T> void DUMP_PROC(tuple<T...> x) {
cerr << "{";
DUMP_PROC(x, index_sequence_for<T...>());
cerr << "}";
}
template <typename T> void DUMP_PROC(vector<T> x) {
cerr << "[";
for (auto &xi : x) {
DUMP_PROC(xi);
cerr << (&xi != &*x.rbegin() ? ", " : "");
}
cerr << "]";
}
template <typename T>
void DUMP_FUNC(T x, const char *name, const char *fn, int ln) {
cerr << "\e[32m[DEBUG]\e[m " << name << ": ";
DUMP_PROC(x);
cerr << " @ " << fn << "(" << ln << ")" << endl;
}
// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
// 標準入出力
struct qin { // query input
size_t sz;
qin(size_t _sz = 1) : sz(_sz) {}
template <typename T> operator T() const {
T a;
cin >> a;
return a;
}
template <typename T> operator vector<T>() const {
vector<T> a(sz);
for (size_t i = 0; i < sz; i++)
cin >> a[i];
return a;
}
template <typename T, typename U> operator pair<T, U>() const {
T f;
U s;
cin >> f >> s;
return pair<T, U>(f, s);
}
};
qin in1; // input one
template <typename T> void say(const T x, const char *end = "\n") {
cout << x << end;
}
void say(const ld x, const char *end = "\n") {
cout << setprecision(30) << x << end;
}
template <typename T>
void say(const vector<T> x, const char *sep = " ", const char *end = "\n") {
REP(i, x.size()) { cout << x[i] << (i + 1 == i_len ? end : sep); }
}
template <typename T>
void say(const vector<vector<T>> x, const char *sep = " ",
const char *end = "\n") {
REP(i, x.size()) { say(x[i], sep, end); }
}
// モジュール
// [[LIBRARY]]
// [[/LIBRARY]]
// 処理内容
int main() {
ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
cin.tie(nullptr); // インタラクティブ問題ではコメントアウトすること
ll k = in1;
ll ans = 0;
ll x = 0;
while (!ans || x % k != 0) {
(x *= 10) %= k;
(x += 7) %= k;
ans++;
if (ans > k * 2) {
say(-1);
}
}
say(ans);
} | // May this submission get accepted
#include <bits/stdc++.h>
// エイリアス
using ll = long signed long;
using ull = long unsigned long;
using ld = long double;
using namespace std;
// AtCoder/Codeforces 用 デバッグ検知
#ifdef ONLINE_JUDGE
constexpr bool DEBUG_MODE = false;
#else
constexpr bool DEBUG_MODE = true;
#endif
// エイリアス (補完・コンパイルが重くなる)
// #include <boost/multiprecision/cpp_int.hpp>
// using mll = boost::multiprecision::cpp_int;
// 汎用マクロ
#define ALLOF(x) (x).begin(), (x).end()
#define REP(i, n) for (long long i = 0, i##_len = (n); i < i##_len; i++)
#define RANGE(i, is, ie) \
for (long long i = (is), i##_end = (ie); i <= i##_end; i++)
#define DSRNG(i, is, ie) \
for (long long i = (is), i##_end = (ie); i >= i##_end; i--)
#define STEP(i, is, ie, step) \
for (long long i = (is), i##_end = (ie), i##_step = (step); i <= i##_end; \
i += i##_step)
#define UNIQUE(v) \
do { \
sort((v).begin(), (v).end()); \
(v).erase(unique((v).begin(), (v).end()), (v).end()); \
} while (false)
#define FOREACH(i, q) for (auto &i : q)
template <typename T, typename U> bool chmax(T &a, const U b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T, typename U> bool chmin(T &a, const U b) {
if (a > b) {
a = b;
return true;
}
return false;
}
constexpr int INF = numeric_limits<int>::max();
constexpr long long LINF = numeric_limits<long long>::max();
constexpr long double EPS = 1e-10L;
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define IIF(q, t, f) ((q) ? (t) : (f))
#define DUMP(q) DUMP_FUNC(q, #q, __FILE__, __LINE__)
template <typename T> void DUMP_PROC(T x) {
if (is_integral<T>() || is_floating_point<T>())
cerr << "\e[32m" << x << "\e[m";
else
cerr << x;
}
template <> void DUMP_PROC<char>(char x) {
cerr << "\e[36m\'" << x << "\'\e[m";
}
template <> void DUMP_PROC<string>(string x) {
cerr << "\e[33m\"" << x << "\"\e[m";
}
template <typename T, typename U> void DUMP_PROC(pair<T, U> x) {
cerr << "{";
DUMP_PROC(x.first);
cerr << ", ";
DUMP_PROC(x.second);
cerr << "}";
}
template <typename... T, typename U, U... Seq>
void DUMP_PROC(tuple<T...> &x, integer_sequence<U, Seq...>) {
(void)(int[]){(cerr << ((const char *[]){"", ", "})[!!Seq]
<< (DUMP_PROC(get<Seq>(x)), ""),
0)...};
}
template <typename... T> void DUMP_PROC(tuple<T...> x) {
cerr << "{";
DUMP_PROC(x, index_sequence_for<T...>());
cerr << "}";
}
template <typename T> void DUMP_PROC(vector<T> x) {
cerr << "[";
for (auto &xi : x) {
DUMP_PROC(xi);
cerr << (&xi != &*x.rbegin() ? ", " : "");
}
cerr << "]";
}
template <typename T>
void DUMP_FUNC(T x, const char *name, const char *fn, int ln) {
cerr << "\e[32m[DEBUG]\e[m " << name << ": ";
DUMP_PROC(x);
cerr << " @ " << fn << "(" << ln << ")" << endl;
}
// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
// 標準入出力
struct qin { // query input
size_t sz;
qin(size_t _sz = 1) : sz(_sz) {}
template <typename T> operator T() const {
T a;
cin >> a;
return a;
}
template <typename T> operator vector<T>() const {
vector<T> a(sz);
for (size_t i = 0; i < sz; i++)
cin >> a[i];
return a;
}
template <typename T, typename U> operator pair<T, U>() const {
T f;
U s;
cin >> f >> s;
return pair<T, U>(f, s);
}
};
qin in1; // input one
template <typename T> void say(const T x, const char *end = "\n") {
cout << x << end;
}
void say(const ld x, const char *end = "\n") {
cout << setprecision(30) << x << end;
}
template <typename T>
void say(const vector<T> x, const char *sep = " ", const char *end = "\n") {
REP(i, x.size()) { cout << x[i] << (i + 1 == i_len ? end : sep); }
}
template <typename T>
void say(const vector<vector<T>> x, const char *sep = " ",
const char *end = "\n") {
REP(i, x.size()) { say(x[i], sep, end); }
}
// モジュール
// [[LIBRARY]]
// [[/LIBRARY]]
// 処理内容
int main() {
ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
cin.tie(nullptr); // インタラクティブ問題ではコメントアウトすること
ll k = in1;
ll ans = 0;
ll x = 0;
while (!ans || x % k != 0) {
(x *= 10) %= k;
(x += 7) %= k;
ans++;
if (ans > k * 2) {
say(-1);
return 0;
}
}
say(ans);
} | insert | 167 | 167 | 167 | 168 | TLE | |
p02596 | C++ | Time Limit Exceeded | // #Sazaの1日1AC
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000000 + 7;
const long long INF = 9e15;
const double PI = 3.14159265358979323846;
// マクロ
// 型エイリアス
using ll = long long;
using P = pair<long long, long long>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vP = vector<pair<long long, long long>>;
// ショートカット
#define rep(i, n) for (long long i = 0; i < n; i++)
#define rep2(i, k, n) for (long long i = k; i < n; i++) // 半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mkp make_pair
// 入力
#define vin(v, N) \
for (long long i = 0; i < N; i++) \
cin >> v.at(i)
#define lin(n) \
long long n; \
cin >> n
#define chin(x) \
char x; \
cin >> x;
#define sin(s) \
string s; \
cin >> s;
#define vlin(v, N) \
vector<long long> v(N); \
for (long long i = 0; i < N; i++) \
cin >> v.at(i)
#define max(a, b) max((ll)a, (ll)b)
#define min(a, b) min((ll)a, (ll)b)
// 関数
// 最大公約数
long long gcd(long long m, long long n) {
long long a = max(m, n);
long long b = min(m, n);
long long r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
// 最小公倍数
long long lcd(long long m, long long n) { return m * n / gcd(m, n); }
// xのn乗
long long power(long long x, long long N) {
long long ret = 1;
for (long long i = 0; i < N; i++)
ret *= x;
return ret;
}
// 繰り返し二乗法
long long repeat_squaring(long long x, long long n) {
if (n == 0)
return 1;
else if (n % 2 == 0) {
long long t = repeat_squaring(x, n / 2);
return t * t % mod;
} else
return x * repeat_squaring(x, n - 1);
}
// 素因数分解(mapで返す)
map<long long, long long> factor(long long p) {
ll p1 = p;
map<long long, long long> ret;
for (long long i = 2; i * i <= p1; i++) {
while (p % i == 0) {
ret[i]++;
p /= i;
}
}
if (p != 1)
ret[p]++;
return ret;
}
// 素数判定
bool is_prime(long long N) {
for (long long i = 2; i * i <= N; i++) {
if (N % i == 0)
return false;
}
return true;
}
// 最大値更新
void chmax(long long &a, long long b) { a = max(a, b); }
// 最小値更新
void chmin(long long &a, long long b) { a = min(a, b); }
// 構造体
// Union-Find木
struct UnionFind {
// メンバ変数
vector<long long> par; // par[i]:=頂点iの親
vector<long long> s; // s[i]:=頂点iが属する集合の個数(iが根のとき)
// コンストラクタ
UnionFind(long long N) : par(N), s(N) {
for (long long i = 0; i < N; i++) {
par[i] = i; // 最初はすべてが根として初期化
s[i] = 1;
}
}
// メンバ関数
// root(i):=頂点iの根
long long root(long long i) {
if (par[i] == i)
return i;
par[i] = root(par[i]); // 経路圧縮
return root(par[i]); // 再帰
}
// size[i]:=iが属する集合の個数
long long size(long long i) { return s[root(i)]; }
// same(x,y) xとyが同じ根を持つか(同じ集合に含まれるか)
bool same(long long x, long long y) { return root(x) == root(y); }
// unite(x,y) xの根をyの根に繋げる(集合を合併)
void unite(long long x, long long y) {
if (!same(x, y)) {
long long rx = root(x);
long long ry = root(y);
par[rx] = par[ry];
s[ry] = s[rx] + s[ry];
}
}
};
/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////
// メイン関数
int main() {
// doubleの桁数
cout << fixed << setprecision(10);
lin(K);
ll N = 0;
ll i = 0;
if (K % 2 == 0) {
cout << -1 << endl;
return 0;
}
while (1) {
i++;
N *= 10;
N += 7;
if (N % K == 0)
break;
N %= K;
}
cout << i << endl;
} | // #Sazaの1日1AC
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000000 + 7;
const long long INF = 9e15;
const double PI = 3.14159265358979323846;
// マクロ
// 型エイリアス
using ll = long long;
using P = pair<long long, long long>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vP = vector<pair<long long, long long>>;
// ショートカット
#define rep(i, n) for (long long i = 0; i < n; i++)
#define rep2(i, k, n) for (long long i = k; i < n; i++) // 半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define mkp make_pair
// 入力
#define vin(v, N) \
for (long long i = 0; i < N; i++) \
cin >> v.at(i)
#define lin(n) \
long long n; \
cin >> n
#define chin(x) \
char x; \
cin >> x;
#define sin(s) \
string s; \
cin >> s;
#define vlin(v, N) \
vector<long long> v(N); \
for (long long i = 0; i < N; i++) \
cin >> v.at(i)
#define max(a, b) max((ll)a, (ll)b)
#define min(a, b) min((ll)a, (ll)b)
// 関数
// 最大公約数
long long gcd(long long m, long long n) {
long long a = max(m, n);
long long b = min(m, n);
long long r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
// 最小公倍数
long long lcd(long long m, long long n) { return m * n / gcd(m, n); }
// xのn乗
long long power(long long x, long long N) {
long long ret = 1;
for (long long i = 0; i < N; i++)
ret *= x;
return ret;
}
// 繰り返し二乗法
long long repeat_squaring(long long x, long long n) {
if (n == 0)
return 1;
else if (n % 2 == 0) {
long long t = repeat_squaring(x, n / 2);
return t * t % mod;
} else
return x * repeat_squaring(x, n - 1);
}
// 素因数分解(mapで返す)
map<long long, long long> factor(long long p) {
ll p1 = p;
map<long long, long long> ret;
for (long long i = 2; i * i <= p1; i++) {
while (p % i == 0) {
ret[i]++;
p /= i;
}
}
if (p != 1)
ret[p]++;
return ret;
}
// 素数判定
bool is_prime(long long N) {
for (long long i = 2; i * i <= N; i++) {
if (N % i == 0)
return false;
}
return true;
}
// 最大値更新
void chmax(long long &a, long long b) { a = max(a, b); }
// 最小値更新
void chmin(long long &a, long long b) { a = min(a, b); }
// 構造体
// Union-Find木
struct UnionFind {
// メンバ変数
vector<long long> par; // par[i]:=頂点iの親
vector<long long> s; // s[i]:=頂点iが属する集合の個数(iが根のとき)
// コンストラクタ
UnionFind(long long N) : par(N), s(N) {
for (long long i = 0; i < N; i++) {
par[i] = i; // 最初はすべてが根として初期化
s[i] = 1;
}
}
// メンバ関数
// root(i):=頂点iの根
long long root(long long i) {
if (par[i] == i)
return i;
par[i] = root(par[i]); // 経路圧縮
return root(par[i]); // 再帰
}
// size[i]:=iが属する集合の個数
long long size(long long i) { return s[root(i)]; }
// same(x,y) xとyが同じ根を持つか(同じ集合に含まれるか)
bool same(long long x, long long y) { return root(x) == root(y); }
// unite(x,y) xの根をyの根に繋げる(集合を合併)
void unite(long long x, long long y) {
if (!same(x, y)) {
long long rx = root(x);
long long ry = root(y);
par[rx] = par[ry];
s[ry] = s[rx] + s[ry];
}
}
};
/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////
// メイン関数
int main() {
// doubleの桁数
cout << fixed << setprecision(10);
lin(K);
ll N = 0;
ll i = 0;
if (K % 2 == 0) {
cout << -1 << endl;
return 0;
}
while (1) {
i++;
N *= 10;
N += 7;
if (N % K == 0)
break;
if (i > 1e7) {
cout << -1 << endl;
return 0;
}
N %= K;
}
cout << i << endl;
} | insert | 165 | 165 | 165 | 170 | TLE | |
p02596 | C++ | Time Limit Exceeded | // #pragma GCC target("avx") // CPU 処理並列化
// #pragma GCC optimize("O3") // CPU 処理並列化
// #pragma GCC optimize("unroll-loops") // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ =
// malloc(size);void * stack_extend_origin_memory_;char *
// stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long
// long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm
// volatile("mov %%rsp, %%rbx\nmov %%rax,
// %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax,
// %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <deque>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
const long long mod = 1000000007;
const long long inf = mod * mod;
const long long d2 = (mod + 1) / 2;
const double EPS = 1e-11;
const double INF = 1e+10;
const double PI = acos(-1.0);
const int C_SIZE = 11100000;
const int UF_SIZE = 3100000;
namespace {
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
inline long long Comb(int a, int b) {
if (a < b || b < 0)
return 0;
return fact[a] * finv[b] % mod * finv[a - b] % mod;
}
void init_C(int n) {
fact[0] = finv[0] = inv[1] = 1;
for (int i = 2; i < n; i++) {
inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
}
for (int i = 1; i < n; i++) {
fact[i] = fact[i - 1] * i % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
long long pw(long long a, long long b) {
if (a < 0LL)
return 0;
if (b < 0LL)
return 0;
long long ret = 1;
while (b) {
if (b % 2)
ret = ret * a % mod;
a = a * a % mod;
b /= 2;
}
return ret;
}
long long pw_mod(long long a, long long b, long long M) {
if (a < 0LL)
return 0;
if (b < 0LL)
return 0;
long long ret = 1;
while (b) {
if (b % 2)
ret = ret * a % M;
a = a * a % M;
b /= 2;
}
return ret;
}
int pw_mod_int(int a, int b, int M) {
if (a < 0)
return 0;
if (b < 0)
return 0;
int ret = 1;
while (b) {
if (b % 2)
ret = (long long)ret * a % M;
a = (long long)a * a % M;
b /= 2;
}
return ret;
}
int ABS(int a) { return max(a, -a); }
long long ABS(long long a) { return max(a, -a); }
double ABS(double a) { return max(a, -a); }
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
int UF[UF_SIZE];
void init_UF(int n) {
for (int i = 0; i < n; i++)
UF[i] = -1;
}
int FIND(int a) {
if (UF[a] < 0)
return a;
return UF[a] = FIND(UF[a]);
}
void UNION(int a, int b) {
a = FIND(a);
b = FIND(b);
if (a == b)
return;
if (UF[a] > UF[b])
swap(a, b);
UF[a] += UF[b];
UF[b] = a;
}
} // namespace
// ここから編集しろ
int main() {
int a;
scanf("%d", &a);
int cur = 7 % a;
int ret = 1;
while (cur) {
cur = (cur * 10 + 7) % a;
ret++;
}
printf("%d\n", ret);
} | // #pragma GCC target("avx") // CPU 処理並列化
// #pragma GCC optimize("O3") // CPU 処理並列化
// #pragma GCC optimize("unroll-loops") // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ =
// malloc(size);void * stack_extend_origin_memory_;char *
// stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long
// long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm
// volatile("mov %%rsp, %%rbx\nmov %%rax,
// %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax,
// %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);
#include <algorithm>
#include <bitset>
#include <cassert>
#include <complex>
#include <deque>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
const long long mod = 1000000007;
const long long inf = mod * mod;
const long long d2 = (mod + 1) / 2;
const double EPS = 1e-11;
const double INF = 1e+10;
const double PI = acos(-1.0);
const int C_SIZE = 11100000;
const int UF_SIZE = 3100000;
namespace {
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
inline long long Comb(int a, int b) {
if (a < b || b < 0)
return 0;
return fact[a] * finv[b] % mod * finv[a - b] % mod;
}
void init_C(int n) {
fact[0] = finv[0] = inv[1] = 1;
for (int i = 2; i < n; i++) {
inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
}
for (int i = 1; i < n; i++) {
fact[i] = fact[i - 1] * i % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
long long pw(long long a, long long b) {
if (a < 0LL)
return 0;
if (b < 0LL)
return 0;
long long ret = 1;
while (b) {
if (b % 2)
ret = ret * a % mod;
a = a * a % mod;
b /= 2;
}
return ret;
}
long long pw_mod(long long a, long long b, long long M) {
if (a < 0LL)
return 0;
if (b < 0LL)
return 0;
long long ret = 1;
while (b) {
if (b % 2)
ret = ret * a % M;
a = a * a % M;
b /= 2;
}
return ret;
}
int pw_mod_int(int a, int b, int M) {
if (a < 0)
return 0;
if (b < 0)
return 0;
int ret = 1;
while (b) {
if (b % 2)
ret = (long long)ret * a % M;
a = (long long)a * a % M;
b /= 2;
}
return ret;
}
int ABS(int a) { return max(a, -a); }
long long ABS(long long a) { return max(a, -a); }
double ABS(double a) { return max(a, -a); }
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
int UF[UF_SIZE];
void init_UF(int n) {
for (int i = 0; i < n; i++)
UF[i] = -1;
}
int FIND(int a) {
if (UF[a] < 0)
return a;
return UF[a] = FIND(UF[a]);
}
void UNION(int a, int b) {
a = FIND(a);
b = FIND(b);
if (a == b)
return;
if (UF[a] > UF[b])
swap(a, b);
UF[a] += UF[b];
UF[b] = a;
}
} // namespace
// ここから編集しろ
int main() {
int a;
scanf("%d", &a);
int cur = 7 % a;
int ret = 1;
while (cur) {
cur = (cur * 10 + 7) % a;
ret++;
if (ret > a) {
ret = -1;
break;
}
}
printf("%d\n", ret);
} | insert | 136 | 136 | 136 | 140 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0); \
cin.sync_with_stdio(0);
long long num;
long long solve(long long mod) {
if (mod == 0) {
return 0;
}
return 1 + solve((mod * 10 + 7) % num);
}
int main() {
cin >> num;
if (num % 2 == 0) {
printf("-1\n");
} else {
cout << solve(7 % num) + 1 << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0); \
cin.sync_with_stdio(0);
long long num;
long long solve(long long mod) {
if (mod == 0) {
return 0;
}
return 1 + solve((mod * 10 + 7) % num);
}
int main() {
cin >> num;
if (num % 2 == 0 || num % 10 == 5) {
printf("-1\n");
} else {
cout << solve(7 % num) + 1 << endl;
}
return 0;
}
| replace | 20 | 21 | 20 | 21 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
ll max(ll a, ll b) {
if (a > b)
return a;
else
return b;
}
ll min(ll a, ll b) {
if (a < b)
return a;
else
return b;
}
ll lowbit(ll x) { return x & (-x); }
ll prime(ll x) {
if (x <= 1)
return false;
for (int i = 2; i <= int(sqrt(x)); i++) {
if (x % i == 0)
return false;
}
return true;
}
bool cmp(ll a, ll b) { return a > b; }
ll gcd(ll a, ll b) {
ll r;
while (b > 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
ll powmod(ll a, ll b, ll mod) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
inline int readint() {
int f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0')
x = x * 10 + ch - '0', ch = getchar();
return f * x;
}
inline ll readll() {
ll f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0')
x = x * 10 + ch - '0', ch = getchar();
return f * x;
}
void fl(string name) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
ll n;
int main() {
cin >> n;
if (n % 2 == 0) {
cout << -1 << endl;
return 0;
}
ll rem = 7, p = 1;
while (rem % n != 0) {
rem = (rem * 10 + 7) % n;
p++;
}
cout << p << endl;
return 0;
}
/* stuff to remember
* int overflow, array bounds
* special cases (n=1? n=0?)
* do something instead of nothing and stay organized
* USE STATIC ARRAYS
* DEFINING ARRAYS BEFORE main()
* DO NOT DEFINE ARRAYS IN main()
* USE INT INSTEAD OF LL,NOTICE THE MLE
*/ | #include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
ll max(ll a, ll b) {
if (a > b)
return a;
else
return b;
}
ll min(ll a, ll b) {
if (a < b)
return a;
else
return b;
}
ll lowbit(ll x) { return x & (-x); }
ll prime(ll x) {
if (x <= 1)
return false;
for (int i = 2; i <= int(sqrt(x)); i++) {
if (x % i == 0)
return false;
}
return true;
}
bool cmp(ll a, ll b) { return a > b; }
ll gcd(ll a, ll b) {
ll r;
while (b > 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
ll powmod(ll a, ll b, ll mod) {
ll res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
inline int readint() {
int f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0')
x = x * 10 + ch - '0', ch = getchar();
return f * x;
}
inline ll readll() {
ll f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0')
x = x * 10 + ch - '0', ch = getchar();
return f * x;
}
void fl(string name) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
ll n;
int main() {
cin >> n;
if (n % 2 == 0 || n % 5 == 0) {
cout << -1 << endl;
return 0;
}
ll rem = 7, p = 1;
while (rem % n != 0) {
rem = (rem * 10 + 7) % n;
p++;
}
cout << p << endl;
return 0;
}
/* stuff to remember
* int overflow, array bounds
* special cases (n=1? n=0?)
* do something instead of nothing and stay organized
* USE STATIC ARRAYS
* DEFINING ARRAYS BEFORE main()
* DO NOT DEFINE ARRAYS IN main()
* USE INT INSTEAD OF LL,NOTICE THE MLE
*/ | replace | 95 | 96 | 95 | 96 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
long long i = 0, k, n;
int main() {
cin >> k;
while (i < 1000000220) {
i++;
n = (n * 10 + 7) % k;
if (n == 0) {
cout << i;
return 0;
}
}
cout << -1;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
long long i = 0, k, n;
int main() {
cin >> k;
while (i < 1000000) {
i++;
n = (n * 10 + 7) % k;
if (n == 0) {
cout << i;
return 0;
}
}
cout << -1;
return 0;
} | replace | 5 | 6 | 5 | 6 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define db(x) cout << x << '\n'
#define db1(x) cout << #x << "=" << x << '\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n'
#define db3(x, y, z) \
cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< '\n'
#define repi(i, n) for (int i = 0; i < (n); ++i)
// #define repA(i,a,n) for(int i=a;i<=(n);++i)
// #define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define err(t) cout << "Error : " << t << endl;
#define all(v) v.begin(), v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007 // 998244353
#define pb push_back
#define rep(i, a, b) for (ll i = a; i <= (b); i++)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vec(a) vector<a>
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
// tree_order_statistics_node_update>;
ll binpow(ll a, ll b) {
if (a == 0)
return 0;
if (b == 0)
return 1;
ll ans = 1;
while (b > 0) {
if (b & 1)
ans = ans * a;
a = a * a;
b = b >> 1;
}
return ans;
}
template <typename T> T Min(T a, T b) { return a < b ? a : b; }
template <typename T> T Max(T a, T b) { return a > b ? a : b; }
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// int n;cin>>n;
// string s;cin>>s;
// ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i];
ll rem;
int k;
cin >> k;
if (k & 1) {
ll t = 1;
rem = 7 % k;
while (rem) {
rem *= 10;
rem += 7;
rem %= k;
t++;
}
db(t);
} else
db(-1);
/*
int test1;cin>>test1;while(test1--){
}
//*/
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define db(x) cout << x << '\n'
#define db1(x) cout << #x << "=" << x << '\n'
#define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << '\n'
#define db3(x, y, z) \
cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
<< '\n'
#define repi(i, n) for (int i = 0; i < (n); ++i)
// #define repA(i,a,n) for(int i=a;i<=(n);++i)
// #define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define err(t) cout << "Error : " << t << endl;
#define all(v) v.begin(), v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007 // 998244353
#define pb push_back
#define rep(i, a, b) for (ll i = a; i <= (b); i++)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vec(a) vector<a>
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
// tree_order_statistics_node_update>;
ll binpow(ll a, ll b) {
if (a == 0)
return 0;
if (b == 0)
return 1;
ll ans = 1;
while (b > 0) {
if (b & 1)
ans = ans * a;
a = a * a;
b = b >> 1;
}
return ans;
}
template <typename T> T Min(T a, T b) { return a < b ? a : b; }
template <typename T> T Max(T a, T b) { return a > b ? a : b; }
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// int n;cin>>n;
// string s;cin>>s;
// ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i];
ll rem;
int k;
cin >> k;
if (k & 1) {
ll t = 1;
rem = 7 % k;
while (rem) {
rem *= 10;
rem += 7;
rem %= k;
t++;
if (t > k) {
db(-1);
return 0;
}
}
db(t);
} else
db(-1);
/*
int test1;cin>>test1;while(test1--){
}
//*/
return 0;
}
| insert | 73 | 73 | 73 | 77 | TLE | |
p02596 | C++ | 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 <= 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;
} | #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;
} | replace | 12 | 13 | 12 | 13 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int K;
cin >> K;
int C = 1;
int M = 7;
if (M % K == 0) {
cout << 1;
} else if (K % 2 == 0) {
cout << -1;
} else {
M = 77 % K;
C = 2;
while (M != 0 && M != (7 % K)) {
C += 1;
M = (M * 10 + 7) % K;
}
if (M == 0) {
cout << C;
} else {
cout << -1;
}
}
} | #include <iostream>
using namespace std;
int main() {
int K;
cin >> K;
int C = 1;
int M = 7;
if (M % K == 0) {
cout << 1;
} else if (K % 2 == 0 || K % 5 == 0) {
cout << -1;
} else {
M = 77 % K;
C = 2;
while (M != 0 && M != (7 % K)) {
C += 1;
M = (M * 10 + 7) % K;
}
if (M == 0) {
cout << C;
} else {
cout << -1;
}
}
} | replace | 10 | 11 | 10 | 11 | TLE | |
p02596 | C++ | 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;
typedef pair<int, int> P;
int main() {
int k;
cin >> k;
ll ans = 0;
if (k % 2 == 0)
cout << -1 << endl;
else {
ll num = 7, col = 1;
while (num % k != 0) {
ans++;
num %= k;
col *= 10;
col %= k;
num += 7 * col;
}
cout << ans + 1 << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
int k;
cin >> k;
ll ans = 0;
if (k % 2 == 0)
cout << -1 << endl;
else if (k % 5 == 0)
cout << -1 << endl;
else {
ll num = 7, col = 1;
while (num % k != 0) {
ans++;
num %= k;
col *= 10;
col %= k;
num += 7 * col;
}
cout << ans + 1 << endl;
}
return 0;
} | insert | 11 | 11 | 11 | 13 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll k;
cin >> k;
if (k % 2 == 0) {
cout << -1 << endl;
return 0;
}
int ans = 1;
ll r = 7 % k;
while (r != 0) {
r = r * 10 + 7;
r %= k;
ans++;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll k;
cin >> k;
if (k % 2 == 0 || k % 5 == 0) {
cout << -1 << endl;
return 0;
}
int ans = 1;
ll r = 7 % k;
while (r != 0) {
r = r * 10 + 7;
r %= k;
ans++;
}
cout << ans << endl;
return 0;
}
| replace | 12 | 13 | 12 | 13 | TLE | |
p02596 | C++ | 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 <= 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();
}
} | #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();
}
} | replace | 55 | 56 | 55 | 56 | TLE | |
p02596 | C++ | Time Limit Exceeded | /*
YATIN KWATRA _03_08_14
Let's Hoop..
__oooo
// / o
/ / | o
| / |__ o
| | __/ o
| | / oooo
| / | _______________________
| | | |_______________________|
|| |___ \__/\_/\_/\/\/\/\/\/\/
|| | \ \/\/\/\/\/\/\/\/\/
|| \ \ \/\/\/\/\/\/\/\/
| | | | \/\/\/\/\/\/\/
| | | | \/\/\/\/\/\/
| | \_/ |\/\/\/\/\/|
\ \ \__ |/\/\/\/\/\|
| \
| |
| |
| |
| |
| |
| |
|________|
|________|
|| |
| | |
| / |
| / /
/\|__________|
| / /
| | /
| | |
\ | \
\ \ \
\ \ |
\ \ |
\ \ |_
\\_/ \
| |
| /
| |
|_/
HOOPER_4_LYF..
*/
// AC BAKSHI RABBA
// #pragma GCC optimize "trapv"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define endl "\n"
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define rfo(i, a, b) for (int i = a; i >= b; i--)
#define vii vector<int>
#define vll vector<ll>
#define pq priority_queue
#define uom unordered_map
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long, long>
#define mll map<ll, ll>
#define mii map<int, int>
#define vvii vector<vii>
#define vvll vector<vll>
#define mod 1000000007
#define MIN -1e9
#define pi 3.1415926535897932384626433832795
using namespace std;
void INPUT() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
/*
-> Check For Overflows
-> Out of Bounds
-> Initialisations of global arrays and variables
-> Read the Question and the sample test cases carefully
-> Its not Always Complex, Try to simplify
-> write it down and try to solve
-> Have Faith in urself and in ur approach
-> If it seems totally out of reach, switch to next :)
-> And Come Back later, if possible ..
o- - - \o __|
o/ /| vv`\
/| | |
| / \_ |
/ \ | |
/ | |
Thats what I call a Tappu / Blocked_shot / Rejection...
Time to Code Now.....
*/
void solve() {
int n;
cin >> n;
if (!(n & 1) and !(n % 5)) {
cout << -1 << endl;
return;
}
ll no = 7;
int ans = 0;
while (1) {
ans++;
if (!(no % n)) {
cout << ans << endl;
return;
}
no %= n;
no = no * 10 + 7;
}
}
int main() {
FIO INPUT();
int t;
t = 1;
// cin >> t;
fo(i, 0, t - 1) { solve(); }
return 0;
}
| /*
YATIN KWATRA _03_08_14
Let's Hoop..
__oooo
// / o
/ / | o
| / |__ o
| | __/ o
| | / oooo
| / | _______________________
| | | |_______________________|
|| |___ \__/\_/\_/\/\/\/\/\/\/
|| | \ \/\/\/\/\/\/\/\/\/
|| \ \ \/\/\/\/\/\/\/\/
| | | | \/\/\/\/\/\/\/
| | | | \/\/\/\/\/\/
| | \_/ |\/\/\/\/\/|
\ \ \__ |/\/\/\/\/\|
| \
| |
| |
| |
| |
| |
| |
|________|
|________|
|| |
| | |
| / |
| / /
/\|__________|
| / /
| | /
| | |
\ | \
\ \ \
\ \ |
\ \ |
\ \ |_
\\_/ \
| |
| /
| |
|_/
HOOPER_4_LYF..
*/
// AC BAKSHI RABBA
// #pragma GCC optimize "trapv"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define endl "\n"
#define fo(i, a, b) for (int i = a; i <= b; i++)
#define rfo(i, a, b) for (int i = a; i >= b; i--)
#define vii vector<int>
#define vll vector<ll>
#define pq priority_queue
#define uom unordered_map
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define pob pop_back
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long, long>
#define mll map<ll, ll>
#define mii map<int, int>
#define vvii vector<vii>
#define vvll vector<vll>
#define mod 1000000007
#define MIN -1e9
#define pi 3.1415926535897932384626433832795
using namespace std;
void INPUT() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
/*
-> Check For Overflows
-> Out of Bounds
-> Initialisations of global arrays and variables
-> Read the Question and the sample test cases carefully
-> Its not Always Complex, Try to simplify
-> write it down and try to solve
-> Have Faith in urself and in ur approach
-> If it seems totally out of reach, switch to next :)
-> And Come Back later, if possible ..
o- - - \o __|
o/ /| vv`\
/| | |
| / \_ |
/ \ | |
/ | |
Thats what I call a Tappu / Blocked_shot / Rejection...
Time to Code Now.....
*/
void solve() {
int n;
cin >> n;
if (!(n & 1) or !(n % 5)) {
cout << -1 << endl;
return;
}
ll no = 7;
int ans = 0;
while (1) {
ans++;
if (!(no % n)) {
cout << ans << endl;
return;
}
no %= n;
no = no * 10 + 7;
}
}
int main() {
FIO INPUT();
int t;
t = 1;
// cin >> t;
fo(i, 0, t - 1) { solve(); }
return 0;
}
| replace | 135 | 136 | 135 | 136 | TLE | |
p02596 | C++ | 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)
cout << -1 << endl;
else {
b = 7;
c = 1;
while (b % a != 0) {
b %= a;
b *= 10;
b += 7;
c++;
}
cout << c << endl;
}
}
| #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;
}
}
| replace | 17 | 18 | 17 | 18 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int, int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const int z = 1000000007;
long long GCD(long long a, long long b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
int main() {
int k;
cin >> k;
int modk7 = 7 % k;
int mod_k = 7 % k;
int ans = 1;
if (k % 2 == 0) {
cout << -1 << endl;
return 0;
}
while (1) {
if (mod_k == 0)
break;
mod_k = (mod_k * 10 + modk7) % k;
ans++;
}
cout << ans << endl;
;
return 0;
}
| #include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort(v.begin(), v.end());
#define VE vector<int>
#define VEP vector<pair<int, int>>
#define llong long long
#define pb(a) push_back(a)
using namespace std;
const vector<VE> DIR{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const int z = 1000000007;
long long GCD(long long a, long long b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
int main() {
int k;
cin >> k;
int modk7 = 7 % k;
int mod_k = 7 % k;
int ans = 1;
if (k % 2 == 0) {
cout << -1 << endl;
return 0;
}
while (1) {
if (ans > 10000000) {
ans = -1;
break;
}
if (mod_k == 0)
break;
mod_k = (mod_k * 10 + modk7) % k;
ans++;
}
cout << ans << endl;
;
return 0;
}
| insert | 39 | 39 | 39 | 43 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned;
using pcc = pair<char, char>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using tuplis = array<ll, 3>;
template <class T> using pq = priority_queue<T, vector<T>, greater<T>>;
const ll LINF = 0x1fffffffffffffff;
const ll MINF = 0x7fffffffffff;
const int INF = 0x3fffffff;
const int MOD = 1000000007;
const int MODD = 998244353;
const ld DINF = numeric_limits<ld>::infinity();
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;
const ll dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
#define overload4(_1, _2, _3, _4, name, ...) name
#define overload3(_1, _2, _3, name, ...) name
/*繰り返し*/
#define rep1(n) for (ll i = 0; i < n; ++i) // n回repeat
#define rep2(i, n) for (ll i = 0; i < n; ++i) // n回repeat(変数指定)
#define rep3(i, a, b) for (ll i = a; i < b; ++i) // a-bまでrepeat
#define rep4(i, a, b, c) \
for (ll i = a; i < b; i += c) // a-bまで公差cでrepeat(等差数列で使えそう)
#define rep(...) \
overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) // repeatまとめ
#define rrep1(n) for (ll i = (n); i--;)
#define rrep2(i, n) for (ll i = (n); i--;)
#define rrep3(i, a, b) for (ll i = (b); i-- > (a);)
#define rrep4(i, a, b, c) for (ll i = a + (b - a - 1) / c * c; i >= a; i -= c)
#define rrep(...) \
overload4(__VA_ARGS__, rrep4, rrep3, rrep2, \
rrep1)(__VA_ARGS__) // 逆repeatまとめ
#define each1(i, a) for (auto &&i : a)
#define each2(x, y, a) for (auto &&[x, y] : a)
#define each3(x, y, z, a) for (auto &&[x, y, z] : a)
#define each(...) \
overload4(__VA_ARGS__, each3, each2, \
each1)(__VA_ARGS__) // 配列の各要素の読み出し
#define all1(i) begin(i), end(i)
#define all2(i, a) begin(i), begin(i) + a
#define all3(i, a, b) begin(i) + a, begin(i) + b
#define all(...) \
overload3(__VA_ARGS__, all3, all2, \
all1)(__VA_ARGS__) // vectorの始めと終わりの読み取り
#define rall1(i) (i).rbegin(), (i).rend()
#define rall2(i, k) (i).rbegin(), (i).rbegin() + k
#define rall3(i, a, b) (i).rbegin() + a, (i).rbegin() + b
#define rall(...) \
overload3(__VA_ARGS__, rall3, rall2, \
rall1)(__VA_ARGS__) // 逆イテレータの取得(rbegin:末尾,rend:頭)
#define sum(...) \
accumulate( \
all(__VA_ARGS__), \
0LL) // vectorの合計(int形で受け付けてしまうので,小数で扱いたい場合はdsumを使う)
#define dsum(...) \
accumulate(all(__VA_ARGS__), 0.0L) // 小数で扱う(long long doubleなど)
#define elif else if
#define unless(a) if (!(a))
#define mp make_pair
#define mt make_tuple
/*標準入力*/
#define INT(...) \
int __VA_ARGS__; \
in(__VA_ARGS__) // int型標準入力受付,以下LDまで同様
#define LL(...) \
ll __VA_ARGS__; \
in(__VA_ARGS__)
#define ULL(...) \
ull __VA_ARGS__; \
in(__VA_ARGS__)
#define STR(...) \
string __VA_ARGS__; \
in(__VA_ARGS__)
#define CHR(...) \
char __VA_ARGS__; \
in(__VA_ARGS__)
#define DBL(...) \
double __VA_ARGS__; \
in(__VA_ARGS__)
#define LD(...) \
ld __VA_ARGS__; \
in(__VA_ARGS__)
/*vector操作*/
#define Sort(a) sort(all(a)) // 昇順ソート
#define RSort(vec) sort(vec.begin(), vec.end(), greater<ll>()) // 降順ソート
#define Rev(a) reverse(all(a)) // 逆順
#define Uniq(a) \
sort(all(a)); \
a.erase(unique(all(a)), end(a))
#define vec(type, name, ...) vector<type> name(__VA_ARGS__) // type型vectorの定義
#define VEC(type, name, size) \
vector<type> name(size); \
in(name) // type型vector(size指定)標準入力受付
#define vv(type, name, h, ...) \
vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w) \
vector<vector<type>> name(h, vector<type>(w)); \
in(name)
#define IV(type, name, size) \
vector<pair<int, int>> name; \
for (int i = 0; i < size; i++) { \
int a_i; \
cin >> a_i; \
name.emplace_back(a_i, i); \
} // Indexつきvector(pair型Vector,(data,index))
#define vvv(type, name, h, w, ...) \
vector<vector<vector<type>>> name( \
h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
template <class T> auto min(const T &a) { return *min_element(all(a)); }
template <class T> auto max(const T &a) { return *max_element(all(a)); }
inline ll popcnt(ull a) { return __builtin_popcountll(a); }
ll gcd(ll a, ll b) {
while (b) {
ll c = b;
b = a % b;
a = c;
}
return a;
}
ll lcm(ll a, ll b) {
if (!a || !b)
return 0;
return a * b / gcd(a, b);
}
ll intpow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans *= a;
a *= a;
b /= 2;
}
return ans;
}
ll modpow(ll a, ll b, ll p) {
ll ans = 1;
while (b) {
if (b & 1)
(ans *= a) %= p;
(a *= a) %= p;
b /= 2;
}
return ans;
}
template <class T, class U> bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
vector<ll> iota(ll n) {
vector<ll> a(n);
iota(a.begin(), a.end(), 0);
return a;
}
vector<pll> factor(ull x) {
vector<pll> ans;
for (ull i = 2; i * i <= x; i++)
if (x % i == 0) {
ans.push_back({i, 1});
while ((x /= i) % i == 0)
ans.back().second++;
}
if (x != 1)
ans.push_back({x, 1});
return ans;
}
map<ll, ll> factor_map(ull x) {
map<ll, ll> ans;
for (ull i = 2; i * i <= x; i++)
if (x % i == 0) {
ans[i] = 1;
while ((x /= i) % i == 0)
ans[i]++;
}
if (x != 1)
ans[x] = 1;
return ans;
}
vector<ll> divisor(ull x) {
vector<ll> ans;
for (ull i = 1; i * i <= x; i++)
if (x % i == 0)
ans.push_back(i);
rrep(ans.size() - (ans.back() * ans.back() == x)) ans.push_back(x / ans[i]);
return ans;
}
template <class T> unordered_map<T, ll> press(vector<T> &a) {
auto b = a;
sort(all(b));
b.erase(unique(all(b)), b.end());
unordered_map<T, ll> ans;
rep(b.size()) ans[b[i]] = i;
each(i, a) i = ans[i];
return ans;
}
template <class T> map<T, ll> press_map(vector<T> &a) {
auto b = a;
sort(all(b));
b.erase(unique(all(b)), b.end());
map<T, ll> ans;
rep(b.size()) ans[b[i]] = i;
each(i, a) i = ans[i];
return ans;
}
int scan() { return getchar(); }
void scan(int &a) { scanf("%d", &a); }
void scan(unsigned &a) { scanf("%u", &a); }
void scan(long &a) { scanf("%ld", &a); }
void scan(long long &a) { scanf("%lld", &a); }
void scan(unsigned long long &a) { scanf("%llu", &a); }
void scan(char &a) {
do {
a = getchar();
} while (a == ' ' || a == '\n');
}
void scan(float &a) { scanf("%f", &a); }
void scan(double &a) { scanf("%lf", &a); }
void scan(long double &a) { scanf("%Lf", &a); }
void scan(vector<bool> &a) {
for (unsigned i = 0; i < a.size(); i++) {
int b;
scan(b);
a[i] = b;
}
}
void scan(char a[]) { scanf("%s", a); }
void scan(string &a) { cin >> a; }
template <class T> void scan(vector<T> &);
template <class T, size_t size> void scan(array<T, size> &);
template <class T, class L> void scan(pair<T, L> &);
template <class T, size_t size> void scan(T (&)[size]);
template <class T> void scan(vector<T> &a) {
for (auto &&i : a)
scan(i);
}
template <class T> void scan(deque<T> &a) {
for (auto &&i : a)
scan(i);
}
template <class T, size_t size> void scan(array<T, size> &a) {
for (auto &&i : a)
scan(i);
}
template <class T, class L> void scan(pair<T, L> &p) {
scan(p.first);
scan(p.second);
}
template <class T, size_t size> void scan(T (&a)[size]) {
for (auto &&i : a)
scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void in() {}
template <class Head, class... Tail> void in(Head &head, Tail &...tail) {
scan(head);
in(tail...);
}
void print() { putchar(' '); }
void print(bool a) { printf("%d", a); }
void print(int a) { printf("%d", a); }
void print(unsigned a) { printf("%u", a); }
void print(long a) { printf("%ld", a); }
void print(long long a) { printf("%lld", a); }
void print(unsigned long long a) { printf("%llu", a); }
void print(char a) { printf("%c", a); }
void print(char a[]) { printf("%s", a); }
void print(const char a[]) { printf("%s", a); }
void print(float a) { printf("%.15f", a); }
void print(double a) { printf("%.15f", a); }
void print(long double a) { printf("%.15Lf", a); }
void print(const string &a) {
for (auto &&i : a)
print(i);
}
template <class T> void print(const vector<T> &);
template <class T, size_t size> void print(const array<T, size> &);
template <class T, class L> void print(const pair<T, L> &p);
template <class T, size_t size> void print(const T (&)[size]);
template <class T> void print(const vector<T> &a) {
if (a.empty())
return;
print(a[0]);
for (auto i = a.begin(); ++i != a.end();) {
putchar(' ');
print(*i);
}
}
template <class T> void print(const deque<T> &a) {
if (a.empty())
return;
print(a[0]);
for (auto i = a.begin(); ++i != a.end();) {
putchar(' ');
print(*i);
}
}
template <class T, size_t size> void print(const array<T, size> &a) {
print(a[0]);
for (auto i = a.begin(); ++i != a.end();) {
putchar(' ');
print(*i);
}
}
template <class T, class L> void print(const pair<T, L> &p) {
print(p.first);
putchar(' ');
print(p.second);
}
template <class T, size_t size> void print(const T (&a)[size]) {
print(a[0]);
for (auto i = a; ++i != end(a);) {
putchar(' ');
print(*i);
}
}
template <class T> void print(const T &a) { cout << a; }
int out() {
putchar('\n');
return 0;
}
template <class T> int out(const T &t) {
print(t);
putchar('\n');
return 0;
} // cout<<t<<endl
template <class Head, class... Tail>
int out(const Head &head, const Tail &...tail) {
print(head);
putchar(' ');
out(tail...);
return 0;
}
#ifdef DEBUG
inline ll __lg(ull __n) {
return sizeof(ull) * __CHAR_BIT__ - 1 - __builtin_clzll(__n);
}
#define debug(...) \
{ \
print(#__VA_ARGS__); \
print(":"); \
out(__VA_ARGS__); \
}
#else
#define debug(...) void(0)
#endif
/*判定出力*/
int first(bool i = true) {
return out(i ? "first" : "second");
} // iがfirstか判断,以下同様
int yes(bool i = true) { return out(i ? "yes" : "no"); }
int Yes(bool i = true) { return out(i ? "Yes" : "No"); }
int No() { return out("No"); }
int YES(bool i = true) { return out(i ? "YES" : "NO"); }
int NO() { return out("NO"); }
int Yay(bool i = true) { return out(i ? "Yay!" : ":("); }
int possible(bool i = true) { return out(i ? "possible" : "impossible"); }
int Possible(bool i = true) { return out(i ? "Possible" : "Impossible"); }
int POSSIBLE(bool i = true) { return out(i ? "POSSIBLE" : "IMPOSSIBLE"); }
void Case(ll i) { printf("Case #%lld: ", i); }
/*vector探索*/
#define bSearch(v, k) \
binary_search(all(v), k) // ソートされた配列vの中の要素にkがあるか(boolean)
#define lowB(v, k) \
lower_bound(all(v), \
k) // ソートされた配列vの中の要素のうちk以上かつ最小のイテレータ
#define DLbetB(v, k) lowB(v, k) - v.begin() // 先頭からの距離
#define DLbetE(v, k) v.end() - lowB(v, k) // 末尾からの距離
#define uppB(v, k) \
upper_bound( \
all(v), \
k) // ソートされた配列vの中の要素のうちkより大きいかつ最小のイテレータ
#define DUbetB(v, k) uppB(v, k) - v.begin() // 先頭からの距離
#define DUbetE(v, k) v.end() - uppB(v, k) // 末尾からの距離
#define Cnt(v, k) count(all(v), k) // 配列vの中で要素kが何個あるかを返す(size_t)
#define CntIf(v, l) \
count_if(all(v), \
l) // 配列vの中で条件式(lambda式)を満たす個数を返す(ex.int num =
// count_if(v.begin(), v.end(), [](int i){return i % 3 == 0;});)
#define Sort2D(myVec, i) \
sort(myVec.begin(), myVec.end(), \
[](const vector<ll> &alpha, const vector<ll> &beta) { \
return alpha[i] < beta[i]; \
}); // i列めでソート
/*最大公約数*/
template <class T> T vgcd(T m, T n) { return gcd(m, n); }
template <class T, class... Args> T vgcd(T a, Args... args) {
return vgcd(a, vgcd(args...));
}
/*階乗*/
ll facctorialMethod(ll k) {
int sum = 1;
for (ll i = 1; i <= k; ++i) {
sum *= i;
// sum%=MOD;//あまりを出力せよ問題の時はこれもやる
}
return sum;
}
/*組み合わせnCk*/
ll comb(const ll N, const ll K) {
vector<vector<long long int>> v(N + 1, vector<long long int>(N + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int k = 1; k < v.size(); k++) {
for (int j = 1; j < k; j++) {
v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
}
}
return v[N][K];
}
/*逆元 あまりの割り算をするときにこいつをかける*/
// mod. m での a の逆元 a^{-1} を計算する
ll modinv(ll a, ll m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
/*ダブリング*/
/*
参考:http://satanic0258.hatenablog.com/entry/2017/02/23/222647
使える場所:1回遷移した先が明確にわかる時
目的:
・ある数XのQ乗を求める
・根付き木において、ある頂点vのQ個上の親を知る
・ある地点からQ回進んだ先を求める
*/
// int N; // 全体の要素数
// int Q;//試行回数
ll doubling(
const ll N, const ll Q,
vector<ll> a) { // cin>>N>>Q;//標準入力から要素数と試行回数を受け取る場合
ll LOG_Q = floor(log2(Q)) + 1;
// next[k][i]で、i番目の要素の「2^k個次の要素」を指す
// (なお、i番目の要素に対して「2^k個次の要素」が存在しないとき、
// next[k][i]が指し示す要素番号を-1とします)
std::vector<std::vector<ll>> next(LOG_Q + 1, std::vector<ll>(N));
// ll a[N];//各要素の次の行き先
// next[0]を計算
for (int i = 0; i < N; ++i) {
next[0][i] = a[i];
}
// nextを計算
for (ll k = 0; k < LOG_Q; ++k) {
for (int i = 0; i < N; ++i) {
if (next[k][i] == -1) {
// 2^k個次に要素が無い時、当然2^(k+1)個次にも要素はありません
next[k + 1][i] = -1;
} else {
// 「2^k個次の要素」の2^k個次の要素は、2^(k+1)個次の要素です
next[k + 1][i] = next[k][next[k][i]];
}
}
}
// ----ここまで準備----
// p番目の要素の「Q個次の要素」を求めることを考えます
ll p = 0;
for (ll k = LOG_Q - 1; k >= 0; --k) {
if (p == -1) {
// pがすでに存在しない要素を指していたら、
// それ以降で存在する要素を指すことはないためループを抜けます
break;
}
if ((Q >> k) & 1) { // ex(Q=5)5=101(2)であり,2^2+2^0回進むことを表す
// Qを二進展開した際、k番目のビットが立っていたら、
// pの位置を2^kだけ次にずらします
p = next[k][p];
}
}
return p; // ここでのpが最終的な答えになる
}
/*素数判定*/
bool IsPrime(ll num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
/*ページのソースを表示->command+F->問題文 で問題文コピペする
*/
// deque<ll> deq;//両端キュー使う,先頭と末尾へのアクセスが早い
// using std::map;
// map<string,ll>memo;//<キー,その要素>,キーの検索が早い,キーは昇順にソートされる
signed main() {
/*以下コード*/
LL(k);
ll ans = -1;
ll num = 7;
rep(LINF) {
if (k % 2 == 0)
break;
if (num % k == 0) {
ans = i + 1;
break;
}
num = (num * 10 + 7) % k;
}
out(ans);
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned;
using pcc = pair<char, char>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using tuplis = array<ll, 3>;
template <class T> using pq = priority_queue<T, vector<T>, greater<T>>;
const ll LINF = 0x1fffffffffffffff;
const ll MINF = 0x7fffffffffff;
const int INF = 0x3fffffff;
const int MOD = 1000000007;
const int MODD = 998244353;
const ld DINF = numeric_limits<ld>::infinity();
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;
const ll dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
#define overload4(_1, _2, _3, _4, name, ...) name
#define overload3(_1, _2, _3, name, ...) name
/*繰り返し*/
#define rep1(n) for (ll i = 0; i < n; ++i) // n回repeat
#define rep2(i, n) for (ll i = 0; i < n; ++i) // n回repeat(変数指定)
#define rep3(i, a, b) for (ll i = a; i < b; ++i) // a-bまでrepeat
#define rep4(i, a, b, c) \
for (ll i = a; i < b; i += c) // a-bまで公差cでrepeat(等差数列で使えそう)
#define rep(...) \
overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) // repeatまとめ
#define rrep1(n) for (ll i = (n); i--;)
#define rrep2(i, n) for (ll i = (n); i--;)
#define rrep3(i, a, b) for (ll i = (b); i-- > (a);)
#define rrep4(i, a, b, c) for (ll i = a + (b - a - 1) / c * c; i >= a; i -= c)
#define rrep(...) \
overload4(__VA_ARGS__, rrep4, rrep3, rrep2, \
rrep1)(__VA_ARGS__) // 逆repeatまとめ
#define each1(i, a) for (auto &&i : a)
#define each2(x, y, a) for (auto &&[x, y] : a)
#define each3(x, y, z, a) for (auto &&[x, y, z] : a)
#define each(...) \
overload4(__VA_ARGS__, each3, each2, \
each1)(__VA_ARGS__) // 配列の各要素の読み出し
#define all1(i) begin(i), end(i)
#define all2(i, a) begin(i), begin(i) + a
#define all3(i, a, b) begin(i) + a, begin(i) + b
#define all(...) \
overload3(__VA_ARGS__, all3, all2, \
all1)(__VA_ARGS__) // vectorの始めと終わりの読み取り
#define rall1(i) (i).rbegin(), (i).rend()
#define rall2(i, k) (i).rbegin(), (i).rbegin() + k
#define rall3(i, a, b) (i).rbegin() + a, (i).rbegin() + b
#define rall(...) \
overload3(__VA_ARGS__, rall3, rall2, \
rall1)(__VA_ARGS__) // 逆イテレータの取得(rbegin:末尾,rend:頭)
#define sum(...) \
accumulate( \
all(__VA_ARGS__), \
0LL) // vectorの合計(int形で受け付けてしまうので,小数で扱いたい場合はdsumを使う)
#define dsum(...) \
accumulate(all(__VA_ARGS__), 0.0L) // 小数で扱う(long long doubleなど)
#define elif else if
#define unless(a) if (!(a))
#define mp make_pair
#define mt make_tuple
/*標準入力*/
#define INT(...) \
int __VA_ARGS__; \
in(__VA_ARGS__) // int型標準入力受付,以下LDまで同様
#define LL(...) \
ll __VA_ARGS__; \
in(__VA_ARGS__)
#define ULL(...) \
ull __VA_ARGS__; \
in(__VA_ARGS__)
#define STR(...) \
string __VA_ARGS__; \
in(__VA_ARGS__)
#define CHR(...) \
char __VA_ARGS__; \
in(__VA_ARGS__)
#define DBL(...) \
double __VA_ARGS__; \
in(__VA_ARGS__)
#define LD(...) \
ld __VA_ARGS__; \
in(__VA_ARGS__)
/*vector操作*/
#define Sort(a) sort(all(a)) // 昇順ソート
#define RSort(vec) sort(vec.begin(), vec.end(), greater<ll>()) // 降順ソート
#define Rev(a) reverse(all(a)) // 逆順
#define Uniq(a) \
sort(all(a)); \
a.erase(unique(all(a)), end(a))
#define vec(type, name, ...) vector<type> name(__VA_ARGS__) // type型vectorの定義
#define VEC(type, name, size) \
vector<type> name(size); \
in(name) // type型vector(size指定)標準入力受付
#define vv(type, name, h, ...) \
vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define VV(type, name, h, w) \
vector<vector<type>> name(h, vector<type>(w)); \
in(name)
#define IV(type, name, size) \
vector<pair<int, int>> name; \
for (int i = 0; i < size; i++) { \
int a_i; \
cin >> a_i; \
name.emplace_back(a_i, i); \
} // Indexつきvector(pair型Vector,(data,index))
#define vvv(type, name, h, w, ...) \
vector<vector<vector<type>>> name( \
h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
template <class T> auto min(const T &a) { return *min_element(all(a)); }
template <class T> auto max(const T &a) { return *max_element(all(a)); }
inline ll popcnt(ull a) { return __builtin_popcountll(a); }
ll gcd(ll a, ll b) {
while (b) {
ll c = b;
b = a % b;
a = c;
}
return a;
}
ll lcm(ll a, ll b) {
if (!a || !b)
return 0;
return a * b / gcd(a, b);
}
ll intpow(ll a, ll b) {
ll ans = 1;
while (b) {
if (b & 1)
ans *= a;
a *= a;
b /= 2;
}
return ans;
}
ll modpow(ll a, ll b, ll p) {
ll ans = 1;
while (b) {
if (b & 1)
(ans *= a) %= p;
(a *= a) %= p;
b /= 2;
}
return ans;
}
template <class T, class U> bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
vector<ll> iota(ll n) {
vector<ll> a(n);
iota(a.begin(), a.end(), 0);
return a;
}
vector<pll> factor(ull x) {
vector<pll> ans;
for (ull i = 2; i * i <= x; i++)
if (x % i == 0) {
ans.push_back({i, 1});
while ((x /= i) % i == 0)
ans.back().second++;
}
if (x != 1)
ans.push_back({x, 1});
return ans;
}
map<ll, ll> factor_map(ull x) {
map<ll, ll> ans;
for (ull i = 2; i * i <= x; i++)
if (x % i == 0) {
ans[i] = 1;
while ((x /= i) % i == 0)
ans[i]++;
}
if (x != 1)
ans[x] = 1;
return ans;
}
vector<ll> divisor(ull x) {
vector<ll> ans;
for (ull i = 1; i * i <= x; i++)
if (x % i == 0)
ans.push_back(i);
rrep(ans.size() - (ans.back() * ans.back() == x)) ans.push_back(x / ans[i]);
return ans;
}
template <class T> unordered_map<T, ll> press(vector<T> &a) {
auto b = a;
sort(all(b));
b.erase(unique(all(b)), b.end());
unordered_map<T, ll> ans;
rep(b.size()) ans[b[i]] = i;
each(i, a) i = ans[i];
return ans;
}
template <class T> map<T, ll> press_map(vector<T> &a) {
auto b = a;
sort(all(b));
b.erase(unique(all(b)), b.end());
map<T, ll> ans;
rep(b.size()) ans[b[i]] = i;
each(i, a) i = ans[i];
return ans;
}
int scan() { return getchar(); }
void scan(int &a) { scanf("%d", &a); }
void scan(unsigned &a) { scanf("%u", &a); }
void scan(long &a) { scanf("%ld", &a); }
void scan(long long &a) { scanf("%lld", &a); }
void scan(unsigned long long &a) { scanf("%llu", &a); }
void scan(char &a) {
do {
a = getchar();
} while (a == ' ' || a == '\n');
}
void scan(float &a) { scanf("%f", &a); }
void scan(double &a) { scanf("%lf", &a); }
void scan(long double &a) { scanf("%Lf", &a); }
void scan(vector<bool> &a) {
for (unsigned i = 0; i < a.size(); i++) {
int b;
scan(b);
a[i] = b;
}
}
void scan(char a[]) { scanf("%s", a); }
void scan(string &a) { cin >> a; }
template <class T> void scan(vector<T> &);
template <class T, size_t size> void scan(array<T, size> &);
template <class T, class L> void scan(pair<T, L> &);
template <class T, size_t size> void scan(T (&)[size]);
template <class T> void scan(vector<T> &a) {
for (auto &&i : a)
scan(i);
}
template <class T> void scan(deque<T> &a) {
for (auto &&i : a)
scan(i);
}
template <class T, size_t size> void scan(array<T, size> &a) {
for (auto &&i : a)
scan(i);
}
template <class T, class L> void scan(pair<T, L> &p) {
scan(p.first);
scan(p.second);
}
template <class T, size_t size> void scan(T (&a)[size]) {
for (auto &&i : a)
scan(i);
}
template <class T> void scan(T &a) { cin >> a; }
void in() {}
template <class Head, class... Tail> void in(Head &head, Tail &...tail) {
scan(head);
in(tail...);
}
void print() { putchar(' '); }
void print(bool a) { printf("%d", a); }
void print(int a) { printf("%d", a); }
void print(unsigned a) { printf("%u", a); }
void print(long a) { printf("%ld", a); }
void print(long long a) { printf("%lld", a); }
void print(unsigned long long a) { printf("%llu", a); }
void print(char a) { printf("%c", a); }
void print(char a[]) { printf("%s", a); }
void print(const char a[]) { printf("%s", a); }
void print(float a) { printf("%.15f", a); }
void print(double a) { printf("%.15f", a); }
void print(long double a) { printf("%.15Lf", a); }
void print(const string &a) {
for (auto &&i : a)
print(i);
}
template <class T> void print(const vector<T> &);
template <class T, size_t size> void print(const array<T, size> &);
template <class T, class L> void print(const pair<T, L> &p);
template <class T, size_t size> void print(const T (&)[size]);
template <class T> void print(const vector<T> &a) {
if (a.empty())
return;
print(a[0]);
for (auto i = a.begin(); ++i != a.end();) {
putchar(' ');
print(*i);
}
}
template <class T> void print(const deque<T> &a) {
if (a.empty())
return;
print(a[0]);
for (auto i = a.begin(); ++i != a.end();) {
putchar(' ');
print(*i);
}
}
template <class T, size_t size> void print(const array<T, size> &a) {
print(a[0]);
for (auto i = a.begin(); ++i != a.end();) {
putchar(' ');
print(*i);
}
}
template <class T, class L> void print(const pair<T, L> &p) {
print(p.first);
putchar(' ');
print(p.second);
}
template <class T, size_t size> void print(const T (&a)[size]) {
print(a[0]);
for (auto i = a; ++i != end(a);) {
putchar(' ');
print(*i);
}
}
template <class T> void print(const T &a) { cout << a; }
int out() {
putchar('\n');
return 0;
}
template <class T> int out(const T &t) {
print(t);
putchar('\n');
return 0;
} // cout<<t<<endl
template <class Head, class... Tail>
int out(const Head &head, const Tail &...tail) {
print(head);
putchar(' ');
out(tail...);
return 0;
}
#ifdef DEBUG
inline ll __lg(ull __n) {
return sizeof(ull) * __CHAR_BIT__ - 1 - __builtin_clzll(__n);
}
#define debug(...) \
{ \
print(#__VA_ARGS__); \
print(":"); \
out(__VA_ARGS__); \
}
#else
#define debug(...) void(0)
#endif
/*判定出力*/
int first(bool i = true) {
return out(i ? "first" : "second");
} // iがfirstか判断,以下同様
int yes(bool i = true) { return out(i ? "yes" : "no"); }
int Yes(bool i = true) { return out(i ? "Yes" : "No"); }
int No() { return out("No"); }
int YES(bool i = true) { return out(i ? "YES" : "NO"); }
int NO() { return out("NO"); }
int Yay(bool i = true) { return out(i ? "Yay!" : ":("); }
int possible(bool i = true) { return out(i ? "possible" : "impossible"); }
int Possible(bool i = true) { return out(i ? "Possible" : "Impossible"); }
int POSSIBLE(bool i = true) { return out(i ? "POSSIBLE" : "IMPOSSIBLE"); }
void Case(ll i) { printf("Case #%lld: ", i); }
/*vector探索*/
#define bSearch(v, k) \
binary_search(all(v), k) // ソートされた配列vの中の要素にkがあるか(boolean)
#define lowB(v, k) \
lower_bound(all(v), \
k) // ソートされた配列vの中の要素のうちk以上かつ最小のイテレータ
#define DLbetB(v, k) lowB(v, k) - v.begin() // 先頭からの距離
#define DLbetE(v, k) v.end() - lowB(v, k) // 末尾からの距離
#define uppB(v, k) \
upper_bound( \
all(v), \
k) // ソートされた配列vの中の要素のうちkより大きいかつ最小のイテレータ
#define DUbetB(v, k) uppB(v, k) - v.begin() // 先頭からの距離
#define DUbetE(v, k) v.end() - uppB(v, k) // 末尾からの距離
#define Cnt(v, k) count(all(v), k) // 配列vの中で要素kが何個あるかを返す(size_t)
#define CntIf(v, l) \
count_if(all(v), \
l) // 配列vの中で条件式(lambda式)を満たす個数を返す(ex.int num =
// count_if(v.begin(), v.end(), [](int i){return i % 3 == 0;});)
#define Sort2D(myVec, i) \
sort(myVec.begin(), myVec.end(), \
[](const vector<ll> &alpha, const vector<ll> &beta) { \
return alpha[i] < beta[i]; \
}); // i列めでソート
/*最大公約数*/
template <class T> T vgcd(T m, T n) { return gcd(m, n); }
template <class T, class... Args> T vgcd(T a, Args... args) {
return vgcd(a, vgcd(args...));
}
/*階乗*/
ll facctorialMethod(ll k) {
int sum = 1;
for (ll i = 1; i <= k; ++i) {
sum *= i;
// sum%=MOD;//あまりを出力せよ問題の時はこれもやる
}
return sum;
}
/*組み合わせnCk*/
ll comb(const ll N, const ll K) {
vector<vector<long long int>> v(N + 1, vector<long long int>(N + 1, 0));
for (int i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (int k = 1; k < v.size(); k++) {
for (int j = 1; j < k; j++) {
v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
}
}
return v[N][K];
}
/*逆元 あまりの割り算をするときにこいつをかける*/
// mod. m での a の逆元 a^{-1} を計算する
ll modinv(ll a, ll m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
/*ダブリング*/
/*
参考:http://satanic0258.hatenablog.com/entry/2017/02/23/222647
使える場所:1回遷移した先が明確にわかる時
目的:
・ある数XのQ乗を求める
・根付き木において、ある頂点vのQ個上の親を知る
・ある地点からQ回進んだ先を求める
*/
// int N; // 全体の要素数
// int Q;//試行回数
ll doubling(
const ll N, const ll Q,
vector<ll> a) { // cin>>N>>Q;//標準入力から要素数と試行回数を受け取る場合
ll LOG_Q = floor(log2(Q)) + 1;
// next[k][i]で、i番目の要素の「2^k個次の要素」を指す
// (なお、i番目の要素に対して「2^k個次の要素」が存在しないとき、
// next[k][i]が指し示す要素番号を-1とします)
std::vector<std::vector<ll>> next(LOG_Q + 1, std::vector<ll>(N));
// ll a[N];//各要素の次の行き先
// next[0]を計算
for (int i = 0; i < N; ++i) {
next[0][i] = a[i];
}
// nextを計算
for (ll k = 0; k < LOG_Q; ++k) {
for (int i = 0; i < N; ++i) {
if (next[k][i] == -1) {
// 2^k個次に要素が無い時、当然2^(k+1)個次にも要素はありません
next[k + 1][i] = -1;
} else {
// 「2^k個次の要素」の2^k個次の要素は、2^(k+1)個次の要素です
next[k + 1][i] = next[k][next[k][i]];
}
}
}
// ----ここまで準備----
// p番目の要素の「Q個次の要素」を求めることを考えます
ll p = 0;
for (ll k = LOG_Q - 1; k >= 0; --k) {
if (p == -1) {
// pがすでに存在しない要素を指していたら、
// それ以降で存在する要素を指すことはないためループを抜けます
break;
}
if ((Q >> k) & 1) { // ex(Q=5)5=101(2)であり,2^2+2^0回進むことを表す
// Qを二進展開した際、k番目のビットが立っていたら、
// pの位置を2^kだけ次にずらします
p = next[k][p];
}
}
return p; // ここでのpが最終的な答えになる
}
/*素数判定*/
bool IsPrime(ll num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false; // 偶数はあらかじめ除く
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
// 素数ではない
return false;
}
}
// 素数である
return true;
}
/*ページのソースを表示->command+F->問題文 で問題文コピペする
*/
// deque<ll> deq;//両端キュー使う,先頭と末尾へのアクセスが早い
// using std::map;
// map<string,ll>memo;//<キー,その要素>,キーの検索が早い,キーは昇順にソートされる
signed main() {
/*以下コード*/
LL(k);
ll ans = -1;
ll num = 7;
rep(1000001) {
if (k % 2 == 0)
break;
if (num % k == 0) {
ans = i + 1;
break;
}
num = (num * 10 + 7) % k;
}
out(ans);
}
| replace | 536 | 537 | 536 | 537 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <fstream>
#include <iostream>
using namespace std;
int const NMAX = 1e6;
bool freq[1 + NMAX];
int main() {
int n, m = 0, ans = 0;
cin >> n;
while (freq[m] == false) {
m = (m * 10 + 7) % n;
ans++;
if (m == 0) {
cout << ans;
return 0;
}
}
cout << -1;
return 0;
}
| #include <fstream>
#include <iostream>
using namespace std;
int const NMAX = 1e6;
bool freq[1 + NMAX];
int main() {
int n, m = 0, ans = 0;
cin >> n;
while (freq[m] == false) {
freq[m] = true;
m = (m * 10 + 7) % n;
ans++;
if (m == 0) {
cout << ans;
return 0;
}
}
cout << -1;
return 0;
}
| insert | 13 | 13 | 13 | 14 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
// ceil(a/b) (a + (b - 1))/ b
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1000000007;
const ll mod = 1000000007;
const double PI = 3.14159265358979323846;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int cans(bool f) {
if (f)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
int main() {
ll ans = 1;
ll K;
cin >> K;
vector<bool> seen(K, false);
ll mod = 7 % K;
if (K % 2 == 0) {
cout << -1 << endl;
return 0;
}
while (1) {
if (mod == 0) {
cout << ans << endl;
return 0;
} else {
seen[mod] = true;
mod = mod * 10 + 7;
mod %= K;
ans++;
}
// cout << mod << endl;
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
// ceil(a/b) (a + (b - 1))/ b
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1000000007;
const ll mod = 1000000007;
const double PI = 3.14159265358979323846;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
ll gcd(ll a, ll b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int cans(bool f) {
if (f)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
int main() {
ll ans = 1;
ll K;
cin >> K;
vector<bool> seen(K, false);
ll mod = 7 % K;
if (K % 2 == 0 || K % 5 == 0) {
cout << -1 << endl;
return 0;
}
while (1) {
if (mod == 0) {
cout << ans << endl;
return 0;
} else {
seen[mod] = true;
mod = mod * 10 + 7;
mod %= K;
ans++;
}
// cout << mod << endl;
}
return 0;
}
| replace | 47 | 48 | 47 | 48 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
int main() {
int k;
cin >> k;
if (k % 2 == 0) {
cout << "-1" << endl;
return 0;
}
int ans = 1, mod = 7 % k;
while (true) {
if (mod == 0) {
cout << ans << endl;
return 0;
}
mod = (mod * 10 + 7) % k;
ans++;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
int main() {
int k;
cin >> k;
if (k % 2 == 0) {
cout << "-1" << endl;
return 0;
}
int ans = 1, mod = 7 % k;
while (true) {
if (mod == 0) {
cout << ans << endl;
return 0;
}
mod = (mod * 10 + 7) % k;
ans++;
if (ans > k) {
cout << "-1" << endl;
return 0;
}
}
} | insert | 22 | 22 | 22 | 26 | TLE | |
p02596 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long lol;
// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (lol i = 0; i < lol(n); i++)
#define REPD(i, n) for (lol i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (lol i = a; i <= lol(b); i++)
#define FORD(i, a, b) for (lol i = a; i >= lol(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) // sizeをsize_tからllに直しておく
// 定数
#define PI 3.1415926535897932385 // pi
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007 // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 最大値最小値
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
lol result{0};
lol k;
cin >> k;
if (k % 2 == 0 || k % 5 == 0) {
cout << -1 << endl;
return 1;
}
lol l;
if (k % 7 == 0)
l = 9 * k / 7;
else {
l = 9 * k;
}
lol re{1};
while (true) {
re = (10 * re) % l;
result++;
// cout << re << endl;
if (re == 1)
break;
}
cout << result << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long lol;
// マクロ
// forループ関係
// 引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (lol i = 0; i < lol(n); i++)
#define REPD(i, n) for (lol i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (lol i = a; i <= lol(b); i++)
#define FORD(i, a, b) for (lol i = a; i >= lol(b); i--)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) // sizeをsize_tからllに直しておく
// 定数
#define PI 3.1415926535897932385 // pi
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007 // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
// 最大値最小値
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
lol result{0};
lol k;
cin >> k;
if (k % 2 == 0 || k % 5 == 0) {
result = -1;
} else {
lol l;
if (k % 7 == 0)
l = 9 * k / 7;
else {
l = 9 * k;
}
lol re{1};
while (true) {
re = (10 * re) % l;
result++;
// cout << re << endl;
if (re == 1)
break;
}
}
cout << result << endl;
return 0;
} | replace | 42 | 58 | 42 | 58 | 0 | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long int ll;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
//*s.find_by_order(p) returns the value of pth largest starting from 0
// s.order_of_key(p) returns no. of items that are strictly < p
// string bin = bitset<64>(m).to_string(); convert decimal m to binary
int main() {
fast;
ll t;
t = 1;
while (t--) {
ll k, a, p;
cin >> k;
if (k == 1) {
cout << "1\n";
continue;
}
if (k % 2 == 0) {
cout << "-1\n";
continue;
}
a = 7;
p = 1;
while (1) {
a = a % k;
if (a == 0) {
cout << p << "\n";
break;
}
p++;
a = 10 * a + 7;
// if(p>100000){break;}
}
}
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long int ll;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define MOD 1000000007
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
//*s.find_by_order(p) returns the value of pth largest starting from 0
// s.order_of_key(p) returns no. of items that are strictly < p
// string bin = bitset<64>(m).to_string(); convert decimal m to binary
int main() {
fast;
ll t;
t = 1;
while (t--) {
ll k, a, p;
cin >> k;
if (k == 1) {
cout << "1\n";
continue;
}
if (k % 2 == 0 || k % 5 == 0) {
cout << "-1\n";
continue;
}
a = 7;
p = 1;
while (1) {
a = a % k;
if (a == 0) {
cout << p << "\n";
break;
}
p++;
a = 10 * a + 7;
// if(p>100000){break;}
}
}
} | replace | 31 | 32 | 31 | 32 | TLE | |
p02596 | Python | Runtime Error | k = int(input())
if k % 7 == 0:
L = 9 * k / 7
else:
L = 9 * k
out = -1
s = 10
for i in range(L):
if s % L == 1:
out = i + 1
break
else:
s = (s % L) * 10
print(out)
| k = int(input())
if k % 7 == 0:
L = 9 * k // 7
else:
L = 9 * k
out = -1
s = 10
for i in range(L):
if s % L == 1:
out = i + 1
break
else:
s = (s % L) * 10
print(out)
| replace | 2 | 3 | 2 | 3 | 0 | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
// #define mp make_pair
#define pii pair<int, int>
#define vec vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define no_of_test(x) \
int x; \
cin >> x; \
while (x--)
const int mod = 1e9 + 7;
void very_fast() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int binary_exponentation(int a, int b) {
int ret = 1;
while (b) {
if (b & 1)
ret = (ret * a) % mod;
b >>= 1;
a = (a * a) % mod;
}
return ret;
}
int32_t main() {
very_fast();
// no_of_test(x)
{
int n;
cin >> n;
if (n % 2 == 0) {
cout << -1 << endl;
return 0;
}
int m = 0;
for (int i = 1; 1 <= 1e7; i++) {
m = (m * 10 + 7) % n;
if (m == 0) {
cout << i << endl;
return 0;
// break;
}
}
cout << -1 << endl;
return 0;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
// #define mp make_pair
#define pii pair<int, int>
#define vec vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define no_of_test(x) \
int x; \
cin >> x; \
while (x--)
const int mod = 1e9 + 7;
void very_fast() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int binary_exponentation(int a, int b) {
int ret = 1;
while (b) {
if (b & 1)
ret = (ret * a) % mod;
b >>= 1;
a = (a * a) % mod;
}
return ret;
}
int32_t main() {
very_fast();
// no_of_test(x)
{
int n;
cin >> n;
if (n % 2 == 0) {
cout << -1 << endl;
return 0;
}
int m = 0;
for (int i = 1; i <= 1e7; i++) {
m = (m * 10 + 7) % n;
if (m == 0) {
cout << i << endl;
return 0;
// break;
}
}
cout << -1 << endl;
return 0;
}
return 0;
}
| replace | 52 | 53 | 52 | 53 | TLE | |
p02596 | C++ | Time Limit Exceeded | #pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
#define int long long
#define all(a) (a).begin(), (a).end()
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i, j, k) mkp(i, mkp(j, k))
#define rng(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) rng(i, 0, (n))
#define mkp make_pair
#define vec vector
#define vi vec<int>
#define pb emplace_back
#define siz(a) (int)(a).size()
#define crdcomp(b) \
sort(all((b))); \
(b).erase(unique(all((b))), (b).end())
#define getidx(b, i) (lower_bound(all(b), (i)) - (b).begin())
#define ssp(i, n) (i == (int)(n)-1 ? "\n" : " ")
#define ctoi(c) (int)(c - '0')
#define itoc(c) (char)(c + '0')
#define cyes printf("Yes\n")
#define cno printf("No\n")
#define cdf(n) \
int quetimes_ = (n); \
rep(qq123_, quetimes_)
#define gcj printf("Case #%lld: ", qq123_ + 1)
#define readv(a, n) \
a.resize(n, 0); \
rep(i, (n)) a[i] = read()
#define found(a, x) (a.find(x) != a.end())
// #define endl "\n"
constexpr int mod = (ll)1e9 + 7;
constexpr int Mod = 998244353;
constexpr ld EPS = 1e-10;
constexpr ll inf = (ll)3 * 1e18;
constexpr int Inf = (ll)15 * 1e8;
constexpr int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
ll read() {
ll u, k = scanf("%lld", &u);
return u;
}
string reads() {
string s;
cin >> s;
return s;
}
H readh(short g = 0) {
H u;
int k = scanf("%lld %lld", &u.fs, &u.sc);
if (g == 1)
u.fs--, u.sc--;
if (g == 2)
u.fs--;
return u;
}
bool ina(H t, int h, int w) {
return 0 <= t.fs && t.fs < h && 0 <= t.sc && t.sc < w;
}
bool ina(int t, int l, int r) { return l <= t && t < r; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll popcount(ll x) {
int sum = 0;
for (int i = 0; i < 60; i++)
if ((1ll << i) & x)
sum++;
return sum;
}
template <typename T> class csum {
vec<T> v;
public:
csum(vec<T> &a) : v(a) { build(); }
csum() {}
void init(vec<T> &a) {
v = a;
build();
}
void build() {
for (int i = 1; i < v.size(); i++)
v[i] += v[i - 1];
}
T a(int l, int r) {
if (r < l)
return 0;
return v[r] - (l == 0 ? 0 : v[l - 1]);
} //[l,r]
T b(int l, int r) { return a(l, r - 1); } //[l,r)
T a(pair<int, int> t) { return a(t.first, t.second); }
T b(pair<int, int> t) { return b(t.first, t.second); }
};
class mint {
public:
ll v;
mint(ll v = 0) { s(v % mod + mod); }
constexpr static int mod = (ll)1e9 + 7;
constexpr static int fn_ = (ll)2e6 + 5;
static mint fact[fn_], comp[fn_];
mint pow(int x) const {
mint b(v), c(1);
while (x) {
if (x & 1)
c *= b;
b *= b;
x >>= 1;
}
return c;
}
inline mint &s(int vv) {
v = vv < mod ? vv : vv - mod;
return *this;
}
inline mint inv() const { return pow(mod - 2); }
inline mint operator-() const { return mint() - *this; }
inline mint &operator+=(const mint b) { return s(v + b.v); }
inline mint &operator-=(const mint b) { return s(v + mod - b.v); }
inline mint &operator*=(const mint b) {
v = v * b.v % mod;
return *this;
}
inline mint &operator/=(const mint b) {
v = v * b.inv().v % mod;
return *this;
}
inline mint operator+(const mint b) const { return mint(v) += b; }
inline mint operator-(const mint b) const { return mint(v) -= b; }
inline mint operator*(const mint b) const { return mint(v) *= b; }
inline mint operator/(const mint b) const { return mint(v) /= b; }
friend ostream &operator<<(ostream &os, const mint &m) { return os << m.v; }
friend istream &operator>>(istream &is, mint &m) {
int x;
is >> x;
m = mint(x);
return is;
}
bool operator<(const mint &r) const { return v < r.v; }
bool operator>(const mint &r) const { return v > r.v; }
bool operator<=(const mint &r) const { return v <= r.v; }
bool operator>=(const mint &r) const { return v >= r.v; }
bool operator==(const mint &r) const { return v == r.v; }
bool operator!=(const mint &r) const { return v != r.v; }
explicit operator bool() const { return v; }
explicit operator int() const { return v; }
mint comb(mint k) {
if (k > *this)
return mint();
if (!fact[0])
combinit();
if (v >= fn_) {
if (k > *this - k)
k = *this - k;
mint tmp(1);
for (int i = v; i >= v - k.v + 1; i--)
tmp *= mint(i);
return tmp * comp[k.v];
}
return fact[v] * comp[k.v] * comp[v - k.v];
} // nCk
mint perm(mint k) {
if (k > *this)
return mint();
if (!fact[0])
combinit();
if (v >= fn_) {
mint tmp(1);
for (int i = v; i >= v - k.v + 1; i--)
tmp *= mint(i);
return tmp;
}
return fact[v] * comp[v - k.v];
} // nPk
static void combinit() {
fact[0] = 1;
for (int i = 1; i < fn_; i++)
fact[i] = fact[i - 1] * mint(i);
comp[fn_ - 1] = fact[fn_ - 1].inv();
for (int i = fn_ - 2; i >= 0; i--)
comp[i] = comp[i + 1] * mint(i + 1);
}
};
mint mint::fact[fn_], mint::comp[fn_];
//--------------------------------------------------------------
//---------------------------------------------------------------------
signed main() {
int k = read();
if (k % 2 == 0) {
cout << -1 << endl;
return 0;
}
int sum = 0, r = 1;
for (int i = 1; i < 100000000; i++) {
(sum += (r * 7) % k) %= k;
;
if (sum == 0) {
cout << i << endl;
return 0;
}
(r *= 10) %= k;
}
cout << -1 << endl;
} | #pragma GCC target("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
#define int long long
#define all(a) (a).begin(), (a).end()
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i, j, k) mkp(i, mkp(j, k))
#define rng(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) rng(i, 0, (n))
#define mkp make_pair
#define vec vector
#define vi vec<int>
#define pb emplace_back
#define siz(a) (int)(a).size()
#define crdcomp(b) \
sort(all((b))); \
(b).erase(unique(all((b))), (b).end())
#define getidx(b, i) (lower_bound(all(b), (i)) - (b).begin())
#define ssp(i, n) (i == (int)(n)-1 ? "\n" : " ")
#define ctoi(c) (int)(c - '0')
#define itoc(c) (char)(c + '0')
#define cyes printf("Yes\n")
#define cno printf("No\n")
#define cdf(n) \
int quetimes_ = (n); \
rep(qq123_, quetimes_)
#define gcj printf("Case #%lld: ", qq123_ + 1)
#define readv(a, n) \
a.resize(n, 0); \
rep(i, (n)) a[i] = read()
#define found(a, x) (a.find(x) != a.end())
// #define endl "\n"
constexpr int mod = (ll)1e9 + 7;
constexpr int Mod = 998244353;
constexpr ld EPS = 1e-10;
constexpr ll inf = (ll)3 * 1e18;
constexpr int Inf = (ll)15 * 1e8;
constexpr int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
ll read() {
ll u, k = scanf("%lld", &u);
return u;
}
string reads() {
string s;
cin >> s;
return s;
}
H readh(short g = 0) {
H u;
int k = scanf("%lld %lld", &u.fs, &u.sc);
if (g == 1)
u.fs--, u.sc--;
if (g == 2)
u.fs--;
return u;
}
bool ina(H t, int h, int w) {
return 0 <= t.fs && t.fs < h && 0 <= t.sc && t.sc < w;
}
bool ina(int t, int l, int r) { return l <= t && t < r; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll popcount(ll x) {
int sum = 0;
for (int i = 0; i < 60; i++)
if ((1ll << i) & x)
sum++;
return sum;
}
template <typename T> class csum {
vec<T> v;
public:
csum(vec<T> &a) : v(a) { build(); }
csum() {}
void init(vec<T> &a) {
v = a;
build();
}
void build() {
for (int i = 1; i < v.size(); i++)
v[i] += v[i - 1];
}
T a(int l, int r) {
if (r < l)
return 0;
return v[r] - (l == 0 ? 0 : v[l - 1]);
} //[l,r]
T b(int l, int r) { return a(l, r - 1); } //[l,r)
T a(pair<int, int> t) { return a(t.first, t.second); }
T b(pair<int, int> t) { return b(t.first, t.second); }
};
class mint {
public:
ll v;
mint(ll v = 0) { s(v % mod + mod); }
constexpr static int mod = (ll)1e9 + 7;
constexpr static int fn_ = (ll)2e6 + 5;
static mint fact[fn_], comp[fn_];
mint pow(int x) const {
mint b(v), c(1);
while (x) {
if (x & 1)
c *= b;
b *= b;
x >>= 1;
}
return c;
}
inline mint &s(int vv) {
v = vv < mod ? vv : vv - mod;
return *this;
}
inline mint inv() const { return pow(mod - 2); }
inline mint operator-() const { return mint() - *this; }
inline mint &operator+=(const mint b) { return s(v + b.v); }
inline mint &operator-=(const mint b) { return s(v + mod - b.v); }
inline mint &operator*=(const mint b) {
v = v * b.v % mod;
return *this;
}
inline mint &operator/=(const mint b) {
v = v * b.inv().v % mod;
return *this;
}
inline mint operator+(const mint b) const { return mint(v) += b; }
inline mint operator-(const mint b) const { return mint(v) -= b; }
inline mint operator*(const mint b) const { return mint(v) *= b; }
inline mint operator/(const mint b) const { return mint(v) /= b; }
friend ostream &operator<<(ostream &os, const mint &m) { return os << m.v; }
friend istream &operator>>(istream &is, mint &m) {
int x;
is >> x;
m = mint(x);
return is;
}
bool operator<(const mint &r) const { return v < r.v; }
bool operator>(const mint &r) const { return v > r.v; }
bool operator<=(const mint &r) const { return v <= r.v; }
bool operator>=(const mint &r) const { return v >= r.v; }
bool operator==(const mint &r) const { return v == r.v; }
bool operator!=(const mint &r) const { return v != r.v; }
explicit operator bool() const { return v; }
explicit operator int() const { return v; }
mint comb(mint k) {
if (k > *this)
return mint();
if (!fact[0])
combinit();
if (v >= fn_) {
if (k > *this - k)
k = *this - k;
mint tmp(1);
for (int i = v; i >= v - k.v + 1; i--)
tmp *= mint(i);
return tmp * comp[k.v];
}
return fact[v] * comp[k.v] * comp[v - k.v];
} // nCk
mint perm(mint k) {
if (k > *this)
return mint();
if (!fact[0])
combinit();
if (v >= fn_) {
mint tmp(1);
for (int i = v; i >= v - k.v + 1; i--)
tmp *= mint(i);
return tmp;
}
return fact[v] * comp[v - k.v];
} // nPk
static void combinit() {
fact[0] = 1;
for (int i = 1; i < fn_; i++)
fact[i] = fact[i - 1] * mint(i);
comp[fn_ - 1] = fact[fn_ - 1].inv();
for (int i = fn_ - 2; i >= 0; i--)
comp[i] = comp[i + 1] * mint(i + 1);
}
};
mint mint::fact[fn_], mint::comp[fn_];
//--------------------------------------------------------------
//---------------------------------------------------------------------
signed main() {
int k = read();
if (k % 2 == 0) {
cout << -1 << endl;
return 0;
}
int sum = 0, r = 1;
for (int i = 1; i < 10000000; i++) {
(sum += (r * 7) % k) %= k;
;
if (sum == 0) {
cout << i << endl;
return 0;
}
(r *= 10) %= k;
}
cout << -1 << endl;
} | replace | 241 | 242 | 241 | 242 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
#define bg begin()
#define en end()
#define pb push_back
#define w(x) \
scanf("%d", &x); \
while (x--)
#define ws(x) \
scanf("%d", &x); \
getchar(); \
while (x--)
#define rep(i, b) for (i = 0; i <= b; i++)
#define ios \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pi 2 * acos(0.0)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const int N = 1e6 + 2;
long long mod = 1e9 + 9;
int t, j, cs = 0, n, b, i, a;
string s;
int main() {
ios scanf("%d", &n);
int a = 0, cnt = 0;
while (a < n) {
a = 10 * a + 7;
cnt++;
}
if (n % 2 == 0) {
printf("-1\n");
return 0;
}
while (a % n != 0) {
a = a % n;
a = a * 10 + 7;
cnt++;
// cout<<a<<endl;
}
printf("%d\n", cnt);
}
| #include <bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
#define bg begin()
#define en end()
#define pb push_back
#define w(x) \
scanf("%d", &x); \
while (x--)
#define ws(x) \
scanf("%d", &x); \
getchar(); \
while (x--)
#define rep(i, b) for (i = 0; i <= b; i++)
#define ios \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pi 2 * acos(0.0)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const int N = 1e6 + 2;
long long mod = 1e9 + 9;
int t, j, cs = 0, n, b, i, a;
string s;
int main() {
ios scanf("%d", &n);
int a = 0, cnt = 0;
while (a < n) {
a = 10 * a + 7;
cnt++;
}
if (n % 2 == 0 || n % 5 == 0) {
printf("-1\n");
return 0;
}
while (a % n != 0) {
a = a % n;
a = a * 10 + 7;
cnt++;
// cout<<a<<endl;
}
printf("%d\n", cnt);
}
| replace | 39 | 40 | 39 | 40 | TLE | |
p02596 | Python | Time Limit Exceeded | K = int(input())
if K % 2 == 0:
print(-1)
else:
mod, modt, ans = 7 % K, 7 % K, 1
while mod != 0:
modt = (modt * (10 % K)) % K
mod, ans = (mod + modt) % K, ans + 1
print(ans)
| K = int(input())
if K % 2 == 0 or K % 5 == 0:
print(-1)
else:
mod, modt, ans = 7 % K, 7 % K, 1
while mod != 0:
modt = (modt * (10 % K)) % K
mod, ans = (mod + modt) % K, ans + 1
print(ans)
| replace | 1 | 2 | 1 | 2 | TLE | |
p02596 | Python | Time Limit Exceeded | K = int(input())
if K % 2 == 0 or K % 5 == 0:
print(-1)
exit()
now = 0
count = 0
while True:
now = now * 10 + 7
count += 1
if now % K == 0:
print(count)
exit()
| K = int(input())
if K % 2 == 0 or K % 5 == 0:
print(-1)
exit()
now = 0
count = 0
while True:
now = (now * 10 + 7) % K
count += 1
if now % K == 0:
print(count)
exit()
| replace | 8 | 9 | 8 | 9 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree <int,null_type,less <int>, rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p) {
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
ll modInverse(ll n, ll p) { return power(n, p - 2, p); }
struct point {
ll x, y;
};
int main() {
FAST
// freopen("input1.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
/*ll tests;
cin>>tests;
rep (gg,0,tests)
{}*/
ll k;
cin >> k;
ll ans = 0;
rep(i, 1, 10000000) {
ll val = 7 * power(10, i - 1, k);
ans += val;
ans %= k;
if (ans == 0) {
cout << i << "\n";
return 0;
}
}
cout << "-1\n";
}
| #include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// typedef tree <int,null_type,less <int>, rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p) {
ll res = 1; // Initialize result
x = x % p; // Update x if it is more than or
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
ll modInverse(ll n, ll p) { return power(n, p - 2, p); }
struct point {
ll x, y;
};
int main() {
FAST
// freopen("input1.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
/*ll tests;
cin>>tests;
rep (gg,0,tests)
{}*/
ll k;
cin >> k;
ll ans = 0;
rep(i, 1, 1000000) {
ll val = 7 * power(10, i - 1, k);
ans += val;
ans %= k;
if (ans == 0) {
cout << i << "\n";
return 0;
}
}
cout << "-1\n";
}
| replace | 53 | 54 | 53 | 54 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
void fastio() {
cin.tie(nullptr);
cin.sync_with_stdio(false);
}
using LL = long long;
using LD = long double;
const LL MOD = 1e9 + 7;
const LL INF = LLONG_MAX;
const LL N = 1e6 + 1;
int main() {
fastio();
LL k;
cin >> k;
LL low = k % 10;
if (low == 2 || low == 4 || low == 5 || low == 6 || low == 8) {
cout << -1 << "\n";
return 0;
}
LL mod = 7 % k, c = 1;
while (mod != 0) {
mod = ((mod * 10) + 7) % k;
c++;
}
cout << c << "\n";
} | #include <bits/stdc++.h>
using namespace std;
void fastio() {
cin.tie(nullptr);
cin.sync_with_stdio(false);
}
using LL = long long;
using LD = long double;
const LL MOD = 1e9 + 7;
const LL INF = LLONG_MAX;
const LL N = 1e6 + 1;
int main() {
fastio();
LL k;
cin >> k;
LL low = k % 10;
if (low == 2 || low == 4 || low == 5 || low == 6 || low == 8 || low == 0) {
cout << -1 << "\n";
return 0;
}
LL mod = 7 % k, c = 1;
while (mod != 0) {
mod = ((mod * 10) + 7) % k;
c++;
}
cout << c << "\n";
} | replace | 24 | 25 | 24 | 25 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define LL long long
#define LLU long long unsigned
#define rarr(arr, n) \
for (int aab = 0; aab < n; aab++) { \
cin >> arr[aab]; \
}
#define parr(arr, n) \
for (int aab = 0; aab < n; aab++) { \
cout << arr[aab] << " "; \
}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";
#define freopen \
freopen("in.txt", "r", stdin); \
freopen("out.txt", "w", stdout); \
ios_base::sync_with_stdio(0); \
cin.tie(0);
int main() {
long long int n;
cin >> n;
if (n % 2 == 0) {
cout << -1;
} else {
long long int ans = 1, number = 7;
while (1) {
if (number % n == 0) {
cout << ans;
return 0;
}
ans++;
number = (number * 10 + 7) % n;
}
}
} | #include <bits/stdc++.h>
using namespace std;
#define LL long long
#define LLU long long unsigned
#define rarr(arr, n) \
for (int aab = 0; aab < n; aab++) { \
cin >> arr[aab]; \
}
#define parr(arr, n) \
for (int aab = 0; aab < n; aab++) { \
cout << arr[aab] << " "; \
}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";
#define freopen \
freopen("in.txt", "r", stdin); \
freopen("out.txt", "w", stdout); \
ios_base::sync_with_stdio(0); \
cin.tie(0);
int main() {
long long int n;
cin >> n;
if (n % 2 == 0 || n % 5 == 0) {
cout << -1;
} else {
long long int ans = 1, number = 7;
while (1) {
if (number % n == 0) {
cout << ans;
return 0;
}
ans++;
number = (number * 10 + 7) % n;
}
}
} | replace | 27 | 28 | 27 | 28 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define f(i, a, b) for (ll i = a; i < b; i++)
#define af(i, a, b) for (ll i = a; i >= b; i--)
#define rep(i, a, b, k) for (ll i = a; i < b; i += k)
#define arep(i, a, b, k) for (ll i = a; i >= b; i -= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort(a.begin(), a.end())
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define inter \
ios::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr)
// policy-based
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
const ll MAX = 3e5 + 100;
const ll inf = 1e12;
const ll mod = 1e9 + 7;
int main() {
fastio;
ll tc, n, x, y, k;
cin >> k;
ll ans = 0, pot = 7, sum = 0;
if (k % 2 == 0 || k == 5) {
cout << "-1\n";
return 0;
}
while (1) {
ans++;
(sum += (pot) % k) %= k;
(pot *= 10) %= k;
if (sum % k == 0)
break;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define f(i, a, b) for (ll i = a; i < b; i++)
#define af(i, a, b) for (ll i = a; i >= b; i--)
#define rep(i, a, b, k) for (ll i = a; i < b; i += k)
#define arep(i, a, b, k) for (ll i = a; i >= b; i -= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort(a.begin(), a.end())
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define inter \
ios::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr)
// policy-based
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
/*
typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
const ll MAX = 3e5 + 100;
const ll inf = 1e12;
const ll mod = 1e9 + 7;
int main() {
fastio;
ll tc, n, x, y, k;
cin >> k;
ll ans = 0, pot = 7, sum = 0;
if (k % 2 == 0 || k % 5 == 0) {
cout << "-1\n";
return 0;
}
while (1) {
ans++;
(sum += (pot) % k) %= k;
(pot *= 10) %= k;
if (sum % k == 0)
break;
}
cout << ans << endl;
} | replace | 54 | 55 | 54 | 55 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = b - 1; i >= a; i--)
#define repl(i, a, b) for (long long i = a; i < b; i++)
#define rrepl(i, a, b) for (long long i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
using pii = pair<int, int>;
using piii = pair<pii, int>;
using pll = pair<long long, long long>;
using plll = pair<pll, long long>;
// #pragma GCC optimize("Ofast")
// #define _GLIBCXX_DEBUG
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define isSquare(x) (sqrt(x) * sqrt(x) == x)
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
};
template <class T> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
};
inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
cin >> first;
in(rest...);
return;
}
inline void out(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void out(First first, Rest... rest) {
cout << first << " ";
out(rest...);
return;
}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
// const int mod = 998244353;
const int INF = 1e9;
const long long INFLL = 1e18;
void iosetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
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...));
}
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T>
pair<S, T> operator*(const pair<S, T> &s, const S &t) {
return pair<S, T>(s.first * t, s.second * t);
}
template <typename T> void Exit(T first) {
cout << first << endl;
exit(0);
};
template <int mod> struct ModInt {
unsigned x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static int get_mod() { return mod; }
};
using modint = ModInt<mod>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const pii dxy[4] = {pii(1, 0), pii(0, 1), pii(-1, 0), pii(0, -1)};
//----------------------- edit from here ---------------------------------
int main() {
iosetup();
int K;
cin >> K;
if (K == 2)
cout << -1 << endl;
else {
int cnt = 1;
ll t = 7;
while (true) {
if (t % K == 0)
Exit(cnt);
t = (t * 10 + 7) % K;
cnt++;
}
}
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits.h>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = b - 1; i >= a; i--)
#define repl(i, a, b) for (long long i = a; i < b; i++)
#define rrepl(i, a, b) for (long long i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
using pii = pair<int, int>;
using piii = pair<pii, int>;
using pll = pair<long long, long long>;
using plll = pair<pll, long long>;
// #pragma GCC optimize("Ofast")
// #define _GLIBCXX_DEBUG
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define isSquare(x) (sqrt(x) * sqrt(x) == x)
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
};
template <class T> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
};
inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First &first, Rest &...rest) {
cin >> first;
in(rest...);
return;
}
inline void out(void) {
cout << "\n";
return;
}
template <typename First, typename... Rest>
void out(First first, Rest... rest) {
cout << first << " ";
out(rest...);
return;
}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
// const int mod = 998244353;
const int INF = 1e9;
const long long INFLL = 1e18;
void iosetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
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...));
}
template <class S, class T>
pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first + t.first, s.second + t.second);
}
template <class S, class T>
pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) {
return pair<S, T>(s.first - t.first, s.second - t.second);
}
template <class S, class T>
pair<S, T> operator*(const pair<S, T> &s, const S &t) {
return pair<S, T>(s.first * t, s.second * t);
}
template <typename T> void Exit(T first) {
cout << first << endl;
exit(0);
};
template <int mod> struct ModInt {
unsigned x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static int get_mod() { return mod; }
};
using modint = ModInt<mod>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const pii dxy[4] = {pii(1, 0), pii(0, 1), pii(-1, 0), pii(0, -1)};
//----------------------- edit from here ---------------------------------
int main() {
iosetup();
int K;
cin >> K;
int cnt = 1;
ll t = 7;
set<int> st;
while (true) {
if (t % K == 0)
Exit(cnt);
st.insert(t);
t = (t * 10 + 7) % K;
if (st.find(t) != st.end())
Exit(-1);
cnt++;
}
return 0;
} | replace | 195 | 206 | 195 | 207 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 200005
const ll INF = 1000000000000000001;
const ll MOD = 1000000007;
// vector< vector<ll> > g(N);
// vector< pair<ll, pair< ll, ll > > > g(N);
// ll vis[N] = {0}, par[N] = {0}, child[N] = {0},cnt = 0;
void solve() {
ll n;
cin >> n;
ll i = 7, cnt = 0;
while (cnt <= 500000000) {
cnt++;
if (i % n == 0) {
cout << cnt << "\n";
return;
}
i *= 10;
i += 7;
i %= n;
}
cout << "-1\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
// ll t;cin >> t;for(ll index=1; index<=t; index++){
// cout << "Case #" << index << ": " ;
solve();
// }
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f(a, b) for (ll i = a; i <= b; i++)
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
#define N 200005
const ll INF = 1000000000000000001;
const ll MOD = 1000000007;
// vector< vector<ll> > g(N);
// vector< pair<ll, pair< ll, ll > > > g(N);
// ll vis[N] = {0}, par[N] = {0}, child[N] = {0},cnt = 0;
void solve() {
ll n;
cin >> n;
ll i = 7, cnt = 0;
while (cnt <= 50000000) {
cnt++;
if (i % n == 0) {
cout << cnt << "\n";
return;
}
i *= 10;
i += 7;
i %= n;
}
cout << "-1\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
// ll t;cin >> t;for(ll index=1; index<=t; index++){
// cout << "Case #" << index << ": " ;
solve();
// }
return 0;
} | replace | 20 | 21 | 20 | 21 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using PII = pair<ll, ll>;
using piii = pair<pii, pii>;
using Pi = pair<int, pii>;
using Graph = vector<vector<int>>;
const int dx[4] = {0, -1, 1, 0};
const int dy[4] = {-1, 0, 0, 1};
bool check(int x, int y) {
if (0 <= x && x < 55 && 0 <= y && y < 55)
return true;
else
return false;
}
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
if (x < y)
swap(x, y);
if (y == 0)
return x;
return gcd(y, x % y);
}
void mul(ll a, ll b) { a = a * b % INF; }
using Graph = vector<vector<int>>;
// iの逆元mod inf
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
const double PI = 3.14159265358979323846;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルをつくる前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1; // mod pにおける1,2,,,nの逆元
for (int i = 2; i < MAX; ++i) {
fac[i] = fac[i - 1] * i % INF;
inv[i] = INF - inv[INF % i] * (INF / i) % INF;
finv[i] = finv[i - 1] * inv[i] % INF;
}
}
ll COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
double Euclidean_distance(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
// 素因数分解
map<int, int> prime_factor(int n) {
map<int, int> res;
for (int i = 2; i * i <= n; ++i) {
while (n % i == 0) {
++res[i];
n /= i;
}
}
if (n != 1)
res[n] = 1;
return res;
}
ll powmod(ll a, ll k, ll mod) {
ll ap = a, ans = 1;
while (k) {
if (k & 1) {
ans *= ap;
ans %= mod;
}
ap = ap * ap;
ap %= mod;
k >>= 1;
}
return ans;
}
ll invi(ll a, ll mod) { return powmod(a, mod - 2, mod); }
#define PI 3.14159265358979323846 // 円周率
// 逆元Aを足したときのmodで割った余りは
//+=invi(A)
// Yで割ることはY^(10^9+7)-2を掛けることは同値
///////////////////////////////////////
int main() {
ll k;
cin >> k;
ll cnt = 1;
ll now = 7;
while (true) {
if (now % k == 0) {
cout << cnt << endl;
return 0;
}
now *= 10;
now += 7;
cnt++;
if (now % k == 0) {
cout << cnt << endl;
return 0;
}
if (now > k)
break;
}
ll key;
key = now % k;
while (true) {
ll a = key;
key *= 10;
key += 7;
key %= k;
cnt++;
if (key == 0)
break;
if (a == key) {
cout << -1 << endl;
return 0;
}
}
cout << cnt << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using PII = pair<ll, ll>;
using piii = pair<pii, pii>;
using Pi = pair<int, pii>;
using Graph = vector<vector<int>>;
const int dx[4] = {0, -1, 1, 0};
const int dy[4] = {-1, 0, 0, 1};
bool check(int x, int y) {
if (0 <= x && x < 55 && 0 <= y && y < 55)
return true;
else
return false;
}
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
if (x < y)
swap(x, y);
if (y == 0)
return x;
return gcd(y, x % y);
}
void mul(ll a, ll b) { a = a * b % INF; }
using Graph = vector<vector<int>>;
// iの逆元mod inf
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
const double PI = 3.14159265358979323846;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルをつくる前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1; // mod pにおける1,2,,,nの逆元
for (int i = 2; i < MAX; ++i) {
fac[i] = fac[i - 1] * i % INF;
inv[i] = INF - inv[INF % i] * (INF / i) % INF;
finv[i] = finv[i - 1] * inv[i] % INF;
}
}
ll COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
double Euclidean_distance(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
// 素因数分解
map<int, int> prime_factor(int n) {
map<int, int> res;
for (int i = 2; i * i <= n; ++i) {
while (n % i == 0) {
++res[i];
n /= i;
}
}
if (n != 1)
res[n] = 1;
return res;
}
ll powmod(ll a, ll k, ll mod) {
ll ap = a, ans = 1;
while (k) {
if (k & 1) {
ans *= ap;
ans %= mod;
}
ap = ap * ap;
ap %= mod;
k >>= 1;
}
return ans;
}
ll invi(ll a, ll mod) { return powmod(a, mod - 2, mod); }
#define PI 3.14159265358979323846 // 円周率
// 逆元Aを足したときのmodで割った余りは
//+=invi(A)
// Yで割ることはY^(10^9+7)-2を掛けることは同値
///////////////////////////////////////
int main() {
ll k;
cin >> k;
ll cnt = 1;
ll now = 7;
while (true) {
if (now % k == 0) {
cout << cnt << endl;
return 0;
}
now *= 10;
now += 7;
cnt++;
if (now % k == 0) {
cout << cnt << endl;
return 0;
}
if (now > k)
break;
}
ll key;
key = now % k;
while (true) {
ll a = key;
key *= 10;
key += 7;
key %= k;
cnt++;
if (key == 0)
break;
if (a == key || cnt >= k) {
cout << -1 << endl;
return 0;
}
}
cout << cnt << endl;
return 0;
}
| replace | 164 | 165 | 164 | 165 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000
using namespace std;
void solve() {
ll k;
cin >> k;
if (k % 2 == 0)
cout << -1 << endl;
else {
ll ans = 1;
ll x = 7;
while (x % k != 0) {
x *= 10;
x += 7;
x %= k;
ans++;
}
cout << ans << endl;
}
}
int32_t main() {
IOS ll T = 1;
// cin >> T;
for (ll i = 1; i <= T; ++i) {
// cout<<"Case #"<<i<<": ";
solve();
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define deb(x) cout << #x << "=" << x << endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000
using namespace std;
void solve() {
ll k;
cin >> k;
if (k % 2 == 0)
cout << -1 << endl;
else {
ll ans = 1;
ll x = 7;
while (x % k != 0) {
if (ans > k) {
cout << -1 << endl;
return;
}
x *= 10;
x += 7;
x %= k;
ans++;
}
cout << ans << endl;
}
}
int32_t main() {
IOS ll T = 1;
// cin >> T;
for (ll i = 1; i <= T; ++i) {
// cout<<"Case #"<<i<<": ";
solve();
}
return 0;
} | insert | 24 | 24 | 24 | 28 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
int main() {
long long ch, i = 1, n, q, k, l, r;
long long j;
cin >> n;
ch = 7;
if (n % 2 != 0) {
while (ch % n != 0) {
i++;
ch = (ch * 10 + 7) % n;
}
cout << i;
} else
cout << -1;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
int main() {
long long ch, i = 1, n, q, k, l, r;
long long j;
cin >> n;
ch = 7;
if (n % 2 != 0) {
while (ch % n != 0) {
i++;
ch = (ch * 10 + 7) % n;
if (i > n) {
cout << -1;
return 0;
}
}
cout << i;
} else
cout << -1;
return 0;
} | insert | 21 | 21 | 21 | 25 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;
using namespace std;
typedef long long ll;
signed main() {
int k;
cin >> k;
if (k % 2 == 0) {
cout << -1 << endl;
return 0;
}
int index = 1;
ll base = 7;
while (true) {
if (base % k == 0)
break;
base %= k;
index++;
base = base * 10 + 7;
}
cout << index << endl;
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;
using namespace std;
typedef long long ll;
signed main() {
int k;
cin >> k;
if (k % 2 == 0) {
cout << -1 << endl;
return 0;
}
int index = 1;
ll base = 7;
while (true) {
if (base % k == 0)
break;
base %= k;
index++;
base = base * 10 + 7;
if (index > 10000000) {
cout << -1 << endl;
return 0;
}
}
cout << index << endl;
return 0;
}
| insert | 28 | 28 | 28 | 32 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define f0(i, a, n) for (i = a; i < n; i++)
#define f1(i, a, n) for (i = a; i <= n; i++)
#define tc(t) \
int t; \
cin >> t; \
while (t--)
#define ini(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define ll long long int
#define vi vector<int>
#define si set<int>
#define pb push_back
#define mp make_pair
#define M 1e9 + 7
#define rr return 0
#define endl '\n'
using namespace std;
void solve() {
ll k, r = 0, cnt = 0;
cin >> k;
if (k % 2 == 0) {
cout << -1 << endl;
} else {
do {
r = ((r * 10) + 7) % k;
cnt++;
} while (r != 0);
cout << cnt << endl;
}
}
int main() {
IOS;
solve();
rr;
} | #include <bits/stdc++.h>
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define f0(i, a, n) for (i = a; i < n; i++)
#define f1(i, a, n) for (i = a; i <= n; i++)
#define tc(t) \
int t; \
cin >> t; \
while (t--)
#define ini(x, y) memset(x, y, sizeof(x))
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define ll long long int
#define vi vector<int>
#define si set<int>
#define pb push_back
#define mp make_pair
#define M 1e9 + 7
#define rr return 0
#define endl '\n'
using namespace std;
void solve() {
ll k, r = 0, cnt = 0;
cin >> k;
if (k % 2 == 0 || k % 5 == 0) {
cout << -1 << endl;
} else {
do {
r = ((r * 10) + 7) % k;
cnt++;
} while (r != 0);
cout << cnt << endl;
}
}
int main() {
IOS;
solve();
rr;
} | replace | 28 | 29 | 28 | 29 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define Rep(i, a, b) for (int i = a; i <= b; i++)
#define _Rep(i, a, b) for (int i = a; i >= b; i--)
#define RepG(i, u) for (int i = head[u]; ~i; i = e[i].next)
typedef long long ll;
const int N = 1e5 + 5;
template <typename T> void read(T &x) {
x = 0;
int f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = (x << 1) + (x << 3) + c - '0';
x *= f;
}
int n;
int main() {
read(n);
if (n % 2 == 0)
return puts("-1"), 0;
int k = 0, ans = 0;
while (1) {
k = k * 10 + 7, k %= n;
ans++;
if (!k)
break;
}
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define Rep(i, a, b) for (int i = a; i <= b; i++)
#define _Rep(i, a, b) for (int i = a; i >= b; i--)
#define RepG(i, u) for (int i = head[u]; ~i; i = e[i].next)
typedef long long ll;
const int N = 1e5 + 5;
template <typename T> void read(T &x) {
x = 0;
int f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = (x << 1) + (x << 3) + c - '0';
x *= f;
}
int n;
int main() {
read(n);
if (n % 2 == 0)
return puts("-1"), 0;
int k = 0, ans = 0;
while (1) {
k = k * 10 + 7, k %= n;
ans++;
if (!k)
break;
if (ans > 5e7)
return puts("-1"), 0;
}
printf("%d\n", ans);
return 0;
} | insert | 35 | 35 | 35 | 37 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define lli long long
#define all(i) i.begin(), i.end()
#define rall(i) i.rbegin(), i.rend()
#define rep0(i, j) for (int i = 0; i < j; i++)
#define rep1(i, j) for (int i = 1; i <= j; i++)
#define rep0d(i, j) for (int i = j - 1; i >= 0; i--)
#define MOD 1000000007
#define MAX (lli)1e12
typedef pair<lli, lli> p;
class Graph {
int V;
vector<list<p>> adj;
const int INF = (int)1e6;
public:
Graph(lli V) : adj(V) { this->V = V; }
void addEdge(int u, int v, int w) { adj[u].push_back(make_pair(v, w)); }
lli edgeNum() {
lli sum = 0;
rep0(i, V) sum += adj[i].size();
return sum;
}
bool route(lli from, lli to) { // vec[i]==j: j->iっていうもとに戻れる道がある
vector<lli> vec(V, -1);
dfs(1, from, vec);
return vec[to] >= 0;
}
void dfs(lli ed, lli num, vector<lli> &vec) {
for (auto e : adj[num]) {
if (vec[e.first] != -1)
continue;
vec[e.first] = num;
dfs(ed + 1, e.first, vec);
}
}
vector<int> bfs(int n) {
queue<int> q;
vector<int> vec(V, -1);
q.push(n);
vec[n] = 0;
while (!q.empty()) {
int p = q.front();
q.pop();
for (auto e : adj[p]) {
if (vec[e.first] == -1) {
q.push(e.first);
vec[e.first] = e.second + vec[p];
}
}
}
return vec;
}
vector<int> shortestPath(int src) {
priority_queue<p, vector<p>, greater<p>> pq;
vector<int> dist(V, INF);
pq.push(make_pair(0, src));
dist[src] = 0;
while (!pq.empty()) {
int u = pq.top().second;
pq.pop();
list<p>::iterator i;
for (auto i = adj[u].begin(); i != adj[u].end(); ++i) {
int v = i->first;
int weight = i->second;
if (dist[v] > dist[u] + weight) {
dist[v] = dist[u] + weight;
pq.push(make_pair(dist[v], v));
}
}
}
for (int i = 0; i < V; i++)
if (dist[i] == INF)
dist[i] = -1;
return dist;
}
};
struct UF {
vector<int> par, size;
UF(int N) : par(N), size(N, 1) { rep0(i, N) par[i] = i; }
int root(int x) {
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry)
return;
par[rx] = ry;
size[rx] += size[ry];
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int getSize(int x) { return size[x]; }
};
struct BIT {
vector<lli> tab; // bit table
BIT(int n) : tab(n + 1) { rep0(i, n + 1) tab[i] = 0; }
void add(int p, lli num) {
for (++p; p < tab.size(); p += p & -p)
tab[p] += num;
}
lli sum(int p) { // from 0 to p
lli ans = 0;
for (++p; p > 0; p -= p & -p)
ans += tab[p];
return ans;
}
void debug() {
rep0(i, tab.size()) cout << tab[i] << ' ';
cout << endl;
}
};
// pairに関するもの
lli sum(p c) { return (c.first + c.second); }
p operator-(const p &l, const p &r) {
return {l.first - r.first, l.second - r.second};
}
bool cmpf(const pair<lli, lli> left, const pair<lli, lli> right) {
return left.first < right.first;
}
bool cmps(const pair<lli, lli> left, const pair<lli, lli> right) {
return left.second < right.second;
}
lli gcd(lli a, lli b) {
if (a < b)
return gcd(b, a);
lli temp;
while ((temp = a % b)) {
a = b;
b = temp;
}
return b;
}
struct nCr {
vector<lli> f, rf;
lli count = 0;
nCr(lli num) : f(num), rf(num) {
count = num;
f[0] = 1;
rep1(i, num) f[i] = (f[i - 1] * i) % MOD;
rep0(i, num + 1) rf[i] = inv(f[i]);
}
lli inv(lli x) {
lli res = 1;
lli k = MOD - 2;
lli y = x;
while (k) {
if (k & 1)
res = (res * y) % MOD;
y = (y * y) % MOD;
k /= 2;
}
return res;
}
lli C(lli n, lli k) {
if (k > n || k < 0)
return 0;
lli a = f[n];
lli b = rf[n - k];
lli c = rf[k];
lli bc = (b * c) % MOD;
return (a * bc) % MOD;
}
};
int main() {
lli n = 7, k, num = 0;
cin >> k;
if (k == 2 || k == 5) {
cout << -1;
return 0;
}
while (n % k != 0) {
n %= k;
n *= 10;
n += 7;
num++;
}
cout << num + 1;
}
| #include <bits/stdc++.h>
using namespace std;
#define lli long long
#define all(i) i.begin(), i.end()
#define rall(i) i.rbegin(), i.rend()
#define rep0(i, j) for (int i = 0; i < j; i++)
#define rep1(i, j) for (int i = 1; i <= j; i++)
#define rep0d(i, j) for (int i = j - 1; i >= 0; i--)
#define MOD 1000000007
#define MAX (lli)1e12
typedef pair<lli, lli> p;
class Graph {
int V;
vector<list<p>> adj;
const int INF = (int)1e6;
public:
Graph(lli V) : adj(V) { this->V = V; }
void addEdge(int u, int v, int w) { adj[u].push_back(make_pair(v, w)); }
lli edgeNum() {
lli sum = 0;
rep0(i, V) sum += adj[i].size();
return sum;
}
bool route(lli from, lli to) { // vec[i]==j: j->iっていうもとに戻れる道がある
vector<lli> vec(V, -1);
dfs(1, from, vec);
return vec[to] >= 0;
}
void dfs(lli ed, lli num, vector<lli> &vec) {
for (auto e : adj[num]) {
if (vec[e.first] != -1)
continue;
vec[e.first] = num;
dfs(ed + 1, e.first, vec);
}
}
vector<int> bfs(int n) {
queue<int> q;
vector<int> vec(V, -1);
q.push(n);
vec[n] = 0;
while (!q.empty()) {
int p = q.front();
q.pop();
for (auto e : adj[p]) {
if (vec[e.first] == -1) {
q.push(e.first);
vec[e.first] = e.second + vec[p];
}
}
}
return vec;
}
vector<int> shortestPath(int src) {
priority_queue<p, vector<p>, greater<p>> pq;
vector<int> dist(V, INF);
pq.push(make_pair(0, src));
dist[src] = 0;
while (!pq.empty()) {
int u = pq.top().second;
pq.pop();
list<p>::iterator i;
for (auto i = adj[u].begin(); i != adj[u].end(); ++i) {
int v = i->first;
int weight = i->second;
if (dist[v] > dist[u] + weight) {
dist[v] = dist[u] + weight;
pq.push(make_pair(dist[v], v));
}
}
}
for (int i = 0; i < V; i++)
if (dist[i] == INF)
dist[i] = -1;
return dist;
}
};
struct UF {
vector<int> par, size;
UF(int N) : par(N), size(N, 1) { rep0(i, N) par[i] = i; }
int root(int x) {
if (par[x] == x)
return x;
return par[x] = root(par[x]);
}
void unite(int x, int y) {
int rx = root(x);
int ry = root(y);
if (rx == ry)
return;
par[rx] = ry;
size[rx] += size[ry];
}
bool same(int x, int y) {
int rx = root(x);
int ry = root(y);
return rx == ry;
}
int getSize(int x) { return size[x]; }
};
struct BIT {
vector<lli> tab; // bit table
BIT(int n) : tab(n + 1) { rep0(i, n + 1) tab[i] = 0; }
void add(int p, lli num) {
for (++p; p < tab.size(); p += p & -p)
tab[p] += num;
}
lli sum(int p) { // from 0 to p
lli ans = 0;
for (++p; p > 0; p -= p & -p)
ans += tab[p];
return ans;
}
void debug() {
rep0(i, tab.size()) cout << tab[i] << ' ';
cout << endl;
}
};
// pairに関するもの
lli sum(p c) { return (c.first + c.second); }
p operator-(const p &l, const p &r) {
return {l.first - r.first, l.second - r.second};
}
bool cmpf(const pair<lli, lli> left, const pair<lli, lli> right) {
return left.first < right.first;
}
bool cmps(const pair<lli, lli> left, const pair<lli, lli> right) {
return left.second < right.second;
}
lli gcd(lli a, lli b) {
if (a < b)
return gcd(b, a);
lli temp;
while ((temp = a % b)) {
a = b;
b = temp;
}
return b;
}
struct nCr {
vector<lli> f, rf;
lli count = 0;
nCr(lli num) : f(num), rf(num) {
count = num;
f[0] = 1;
rep1(i, num) f[i] = (f[i - 1] * i) % MOD;
rep0(i, num + 1) rf[i] = inv(f[i]);
}
lli inv(lli x) {
lli res = 1;
lli k = MOD - 2;
lli y = x;
while (k) {
if (k & 1)
res = (res * y) % MOD;
y = (y * y) % MOD;
k /= 2;
}
return res;
}
lli C(lli n, lli k) {
if (k > n || k < 0)
return 0;
lli a = f[n];
lli b = rf[n - k];
lli c = rf[k];
lli bc = (b * c) % MOD;
return (a * bc) % MOD;
}
};
int main() {
lli n = 7, k, num = 0;
cin >> k;
if (k % 2 == 0 || k % 5 == 0) {
cout << -1;
return 0;
}
while (n % k != 0) {
n %= k;
n *= 10;
n += 7;
num++;
}
cout << num + 1;
}
| replace | 200 | 201 | 200 | 201 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl '\n'
#ifndef CODE_JAM
#undef CASE_INFO
#endif
#else
#pragma GCC optimize "trapv"
#endif
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(n) for (int i = 0; i < n; i++)
#define repj(n) for (int j = 0; j < n; j++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
template <class X = int> inline X mid(X s, X e) { return (s + (e - s) / 2); }
template <class X = int> inline X len(X s, X e) { return (e - s + 1); }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int oo = 987654321;
const ll OO = 1e18;
class Timer {
public:
clock_t start;
Timer() { start = clock(); }
~Timer() { cerr << (double)(clock() - start) / CLOCKS_PER_SEC << "\n"; }
};
void solve() {
int k;
cin >> k;
set<int> s;
int cur = 7 % k;
int steps = 1;
s.insert(cur);
while (1) {
if (cur == 0) {
cout << steps << endl;
return;
}
cur = ((cur * 10) + 7) % k;
if (cur != 0 and s.count(cur)) {
cout << "-1\n";
return;
}
steps++;
}
}
signed main() {
Timer ti;
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
#ifdef TEST_CASES
cin >> T;
#endif
for (int t = 1; t <= T; t++) {
#ifdef CASE_INFO
cout << "Case #" << t << ": ";
#endif
solve();
}
return 0;
}
| #include <bits/stdc++.h>
#ifdef ONLINE_JUDGE
#define endl '\n'
#ifndef CODE_JAM
#undef CASE_INFO
#endif
#else
#pragma GCC optimize "trapv"
#endif
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(n) for (int i = 0; i < n; i++)
#define repj(n) for (int j = 0; j < n; j++)
#define all(p) p.begin(), p.end()
#define count_1(p) __builtin_popcountll(p)
#define count_0(p) __builtin_ctzll(p)
using namespace std;
template <class X = int> inline X mid(X s, X e) { return (s + (e - s) / 2); }
template <class X = int> inline X len(X s, X e) { return (e - s + 1); }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int oo = 987654321;
const ll OO = 1e18;
class Timer {
public:
clock_t start;
Timer() { start = clock(); }
~Timer() { cerr << (double)(clock() - start) / CLOCKS_PER_SEC << "\n"; }
};
void solve() {
int k;
cin >> k;
set<int> s;
int cur = 7 % k;
int steps = 1;
s.insert(cur);
while (1) {
if (cur == 0) {
cout << steps << endl;
return;
}
cur = ((cur * 10) + 7) % k;
if (cur != 0 and s.count(cur)) {
cout << "-1\n";
return;
}
s.insert(cur);
steps++;
}
}
signed main() {
Timer ti;
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int T = 1;
#ifdef TEST_CASES
cin >> T;
#endif
for (int t = 1; t <= T; t++) {
#ifdef CASE_INFO
cout << "Case #" << t << ": ";
#endif
solve();
}
return 0;
}
| insert | 59 | 59 | 59 | 60 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using bl = bool;
using vbl = std::vector<bl>;
using vvbl = std::vector<vbl>;
using vvvbl = std::vector<vvbl>;
using ss = string;
using vss = std::vector<ss>;
#define rep(i, n) for (ll(i) = 0; (i) < (ll)(n); (i)++)
#define repm(i, n, m) for (ll(i) = m; (i) < (ll)(n); (i)++)
#define repi(i, n) for (ll(i) = (n - 1); (i) >= (ll)(0); (i)--)
#define repit(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
#define println(v) \
{ \
ll i = 0; \
for (auto(a) : v) { \
cerr << setw(2) << i << " : " << a << endl; \
i++; \
} \
}
template <class T> void printsp(vector<T> v, size_t w = 3) {
for (auto(a) : v) {
cerr << setw(w) << a << " ";
}
cerr << endl;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> void bye(T a) {
cout << a << '\n';
exit(0);
}
template <class T1, class T2> void bye(T1 a, T2 b) {
cout << a << " " << b << '\n';
exit(0);
}
template <class T1, class T2, class T3> void bye(T1 a, T2 b, T3 c) {
cout << a << " " << b << " " << c << '\n';
exit(0);
}
template <class T> void bye(vector<T> A) {
rep(i, (ll)A.size()) {
cout << A[i];
if (i != (ll)A.size() - 1) {
cout << " ";
}
}
cout << endl;
exit(0);
}
// vector
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// vector<string>
ostream &operator<<(ostream &os, const vector<string> &vec) {
ll N = to_string((ll)vec.size()).length();
string head;
rep(i, N + 2) { head += "-"; }
rep(i, 40) { head += to_string(i % 10); }
os << setw(N) << head << endl;
for (ll i = 0; i < (ll)vec.size(); i++) {
os << setw(N) << i << ": " << vec[i] << endl;
}
return os;
}
// vector<ll>
ostream &operator<<(ostream &os, const vector<ll> &vec) {
ll N = to_string((ll)vec.size()).length();
for (ll i = 0; i < (ll)vec.size(); i++) {
os << setw(N) << i << ": " << vec[i] << endl;
}
return os;
}
// vector<ld>
ostream &operator<<(ostream &os, const vector<ld> &vec) {
ll N = to_string((ll)vec.size()).length();
for (ll i = 0; i < (ll)vec.size(); i++) {
os << setw(N) << i << ": " << vec[i] << endl;
// os <<vec[i] << endl;
}
return os;
}
// vvll
ostream &operator<<(ostream &os, const vector<vector<ll>> &mat) {
ll keta = 1;
rep(i, mat.size()) {
rep(j, mat[i].size()) {
ll x = mat[i][j];
chmax(keta, (ll)to_string(x).length());
}
}
ll N = to_string((ll)mat.size()).length();
rep(i, mat.size()) {
os << setw(N) << i << ": ";
rep(j, mat[i].size()) {
ll x = mat[i][j];
os << setw(keta + 1) << x;
}
os << endl;
}
return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (ll i = 0; i < (ll)vec.size(); i++) {
// os << setw(3) <<i <<" : "<< setw(5) << vec[i] << endl;
os << setw(5) << vec[i];
}
os << endl;
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
os << "{";
repit(itr, map_var) {
// for(auto itr : map_var) {
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
os << "{";
repit(itr, set_var) {
// for( auto itr : set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
#define DUMPOUT cerr
#define DUMPCOLOR ("\033[36m")
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << DUMPCOLOR;
DUMPOUT << head;
if (sizeof...(Tail) > 0) {
DUMPOUT << ", ";
}
dump_func(std::move(tail)...);
DUMPOUT << "\033[m";
}
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << DUMPCOLOR << "" << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< "\033[m" \
<< "", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
struct Fast {
Fast() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
}
} fast;
inline vll cinvll(ll N, ll minus = 0) {
vll A(N);
rep(i, N) {
cin >> A[i];
A[i] -= minus;
}
return move(A);
}
inline vvll zerosll(ll H, ll W, ll val = 0) {
vvll A(H, vll(W, val));
return move(A);
}
inline vvvll zerosll3(ll H, ll W, ll C, ll val = 0) {
vvvll A(H, vvll(W, vll(C, val)));
return move(A);
}
vvll cinvll2(ll H, ll W, ll bias = 0) {
vvll A = zerosll(H, W);
rep(i, H) {
rep(j, W) {
cin >> A[i][j];
A[i][j] += bias;
}
}
return move(A);
}
tuple<vll, vll> aho2(ll N) {
vll A(N), B(N);
rep(i, N) { cin >> A[i] >> B[i]; }
return (make_tuple(A, B));
}
template <class T = ll> inline vector<T> cinv(ll N, T val = 0) {
vector<T> v(N);
rep(i, N) {
cin >> v[i];
v[i] += val;
}
return move(v);
}
template <class T = ll> inline vector<vector<T>> zeros(ll H, ll W, T val = 0) {
vector<vector<T>> A(H, vector<T>(W, val));
return move(A);
}
template <class T = ll>
inline vector<vector<vector<T>>> zeros3(ll H, ll W, ll C, T val = 0) {
vector<vector<vector<T>>> A(H, vector<vector<T>>(W, vector<T>(C, val)));
return move(A);
}
template <typename TTT>
vector<ll> arg_sort(const vector<TTT> &A, bool ascend = true) {
vector<ll> index(A.size());
iota(index.begin(), index.end(), 0);
if (ascend) {
std::sort(all(index), [&A](TTT i1, TTT i2) { return A[i1] < A[i2]; });
} else {
std::sort(all(index), [&A](TTT i1, TTT i2) { return A[i1] > A[i2]; });
}
return index;
}
template <typename TTT> vector<TTT> permute(vector<TTT> src, vll idx) {
vector<TTT> dst(src.size());
rep(i, src.size()) { dst[i] = src[idx[i]]; }
return move(dst);
}
void funcA() {
ll N;
cin >> N;
if (N >= 30) {
bye("Yes");
}
bye("No");
}
void func() {
ll N;
cin >> N;
if (N % 2 == 0) {
bye(-1);
}
ll cnt = 1;
ll M = 7;
while (M != 0) {
while (M < N) {
M = M * 10 + 7;
cnt += 1;
}
M %= N;
}
bye(cnt);
}
void funcD() {
ll N;
cin >> N;
ss S;
cin >> S;
N = S.length();
ll cnt = 0;
ll w, r;
w = 0;
r = N - 1;
while (true) {
dump(S, cnt);
while (w < N) {
if (S[w] == 'W') {
break;
}
w += 1;
}
while (r >= 0) {
if (S[r] == 'R') {
break;
}
r -= 1;
}
if (w < r) {
swap(S[w], S[r]);
cnt += 1;
} else {
break;
}
}
bye(cnt);
}
#if 0
vld A;
ll N,K;
bool isOK(ld mid){
ll cnt =0;
rep(i,N){
cnt += (ll)(ceill(A[i] / mid)-1.0);
}
if(cnt<=K){
return true;
}
return false;
}
void func(){
cin >> N >>K;
A.resize(N);
rep(i,N){
cin >> A[i];
}
ld a_max=0;
rep(i,N){
chmax(a_max,A[i]);
}
ld ok = a_max;
ld ng = 0.0;
dump(ok,ng);
/* ok と ng のどちらが大きいかわからないことを考慮 */
ll cnt = 0;
while (abs(ok - ng) > 1e-8) {
ld mid = (ok + ng) / 2;
//dump(ok,ng,mid);
if (isOK(mid)) ok = mid;
else ng = mid;
cnt ++;
if(cnt>10000){
break;
}
}
dump(ok,ng);
ll ans = (ll)ceill(ng);
dump(cnt);
bye(ans);
}
#endif
int main() {
dump("start");
func();
return 0;
}
| #include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using bl = bool;
using vbl = std::vector<bl>;
using vvbl = std::vector<vbl>;
using vvvbl = std::vector<vvbl>;
using ss = string;
using vss = std::vector<ss>;
#define rep(i, n) for (ll(i) = 0; (i) < (ll)(n); (i)++)
#define repm(i, n, m) for (ll(i) = m; (i) < (ll)(n); (i)++)
#define repi(i, n) for (ll(i) = (n - 1); (i) >= (ll)(0); (i)--)
#define repit(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define all(v) v.begin(), v.end()
#define println(v) \
{ \
ll i = 0; \
for (auto(a) : v) { \
cerr << setw(2) << i << " : " << a << endl; \
i++; \
} \
}
template <class T> void printsp(vector<T> v, size_t w = 3) {
for (auto(a) : v) {
cerr << setw(w) << a << " ";
}
cerr << endl;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> void bye(T a) {
cout << a << '\n';
exit(0);
}
template <class T1, class T2> void bye(T1 a, T2 b) {
cout << a << " " << b << '\n';
exit(0);
}
template <class T1, class T2, class T3> void bye(T1 a, T2 b, T3 c) {
cout << a << " " << b << " " << c << '\n';
exit(0);
}
template <class T> void bye(vector<T> A) {
rep(i, (ll)A.size()) {
cout << A[i];
if (i != (ll)A.size() - 1) {
cout << " ";
}
}
cout << endl;
exit(0);
}
// vector
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (T &x : vec)
is >> x;
return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// vector<string>
ostream &operator<<(ostream &os, const vector<string> &vec) {
ll N = to_string((ll)vec.size()).length();
string head;
rep(i, N + 2) { head += "-"; }
rep(i, 40) { head += to_string(i % 10); }
os << setw(N) << head << endl;
for (ll i = 0; i < (ll)vec.size(); i++) {
os << setw(N) << i << ": " << vec[i] << endl;
}
return os;
}
// vector<ll>
ostream &operator<<(ostream &os, const vector<ll> &vec) {
ll N = to_string((ll)vec.size()).length();
for (ll i = 0; i < (ll)vec.size(); i++) {
os << setw(N) << i << ": " << vec[i] << endl;
}
return os;
}
// vector<ld>
ostream &operator<<(ostream &os, const vector<ld> &vec) {
ll N = to_string((ll)vec.size()).length();
for (ll i = 0; i < (ll)vec.size(); i++) {
os << setw(N) << i << ": " << vec[i] << endl;
// os <<vec[i] << endl;
}
return os;
}
// vvll
ostream &operator<<(ostream &os, const vector<vector<ll>> &mat) {
ll keta = 1;
rep(i, mat.size()) {
rep(j, mat[i].size()) {
ll x = mat[i][j];
chmax(keta, (ll)to_string(x).length());
}
}
ll N = to_string((ll)mat.size()).length();
rep(i, mat.size()) {
os << setw(N) << i << ": ";
rep(j, mat[i].size()) {
ll x = mat[i][j];
os << setw(keta + 1) << x;
}
os << endl;
}
return os;
}
// vector
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (ll i = 0; i < (ll)vec.size(); i++) {
// os << setw(3) <<i <<" : "<< setw(5) << vec[i] << endl;
os << setw(5) << vec[i];
}
os << endl;
return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
os << "{";
repit(itr, map_var) {
// for(auto itr : map_var) {
os << *itr;
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
// set
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
os << "{";
repit(itr, set_var) {
// for( auto itr : set_var) {
os << *itr;
itr++;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
#define DUMPOUT cerr
#define DUMPCOLOR ("\033[36m")
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << DUMPCOLOR;
DUMPOUT << head;
if (sizeof...(Tail) > 0) {
DUMPOUT << ", ";
}
dump_func(std::move(tail)...);
DUMPOUT << "\033[m";
}
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << DUMPCOLOR << "" << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< "\033[m" \
<< "", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
struct Fast {
Fast() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
}
} fast;
inline vll cinvll(ll N, ll minus = 0) {
vll A(N);
rep(i, N) {
cin >> A[i];
A[i] -= minus;
}
return move(A);
}
inline vvll zerosll(ll H, ll W, ll val = 0) {
vvll A(H, vll(W, val));
return move(A);
}
inline vvvll zerosll3(ll H, ll W, ll C, ll val = 0) {
vvvll A(H, vvll(W, vll(C, val)));
return move(A);
}
vvll cinvll2(ll H, ll W, ll bias = 0) {
vvll A = zerosll(H, W);
rep(i, H) {
rep(j, W) {
cin >> A[i][j];
A[i][j] += bias;
}
}
return move(A);
}
tuple<vll, vll> aho2(ll N) {
vll A(N), B(N);
rep(i, N) { cin >> A[i] >> B[i]; }
return (make_tuple(A, B));
}
template <class T = ll> inline vector<T> cinv(ll N, T val = 0) {
vector<T> v(N);
rep(i, N) {
cin >> v[i];
v[i] += val;
}
return move(v);
}
template <class T = ll> inline vector<vector<T>> zeros(ll H, ll W, T val = 0) {
vector<vector<T>> A(H, vector<T>(W, val));
return move(A);
}
template <class T = ll>
inline vector<vector<vector<T>>> zeros3(ll H, ll W, ll C, T val = 0) {
vector<vector<vector<T>>> A(H, vector<vector<T>>(W, vector<T>(C, val)));
return move(A);
}
template <typename TTT>
vector<ll> arg_sort(const vector<TTT> &A, bool ascend = true) {
vector<ll> index(A.size());
iota(index.begin(), index.end(), 0);
if (ascend) {
std::sort(all(index), [&A](TTT i1, TTT i2) { return A[i1] < A[i2]; });
} else {
std::sort(all(index), [&A](TTT i1, TTT i2) { return A[i1] > A[i2]; });
}
return index;
}
template <typename TTT> vector<TTT> permute(vector<TTT> src, vll idx) {
vector<TTT> dst(src.size());
rep(i, src.size()) { dst[i] = src[idx[i]]; }
return move(dst);
}
void funcA() {
ll N;
cin >> N;
if (N >= 30) {
bye("Yes");
}
bye("No");
}
void func() {
ll N;
cin >> N;
if (N % 2 == 0) {
bye(-1);
}
ll cnt = 1;
ll M = 7;
while (M != 0) {
while (M < N) {
M = M * 10 + 7;
cnt += 1;
}
M %= N;
if (cnt > 1000000) {
bye(-1);
}
}
bye(cnt);
}
void funcD() {
ll N;
cin >> N;
ss S;
cin >> S;
N = S.length();
ll cnt = 0;
ll w, r;
w = 0;
r = N - 1;
while (true) {
dump(S, cnt);
while (w < N) {
if (S[w] == 'W') {
break;
}
w += 1;
}
while (r >= 0) {
if (S[r] == 'R') {
break;
}
r -= 1;
}
if (w < r) {
swap(S[w], S[r]);
cnt += 1;
} else {
break;
}
}
bye(cnt);
}
#if 0
vld A;
ll N,K;
bool isOK(ld mid){
ll cnt =0;
rep(i,N){
cnt += (ll)(ceill(A[i] / mid)-1.0);
}
if(cnt<=K){
return true;
}
return false;
}
void func(){
cin >> N >>K;
A.resize(N);
rep(i,N){
cin >> A[i];
}
ld a_max=0;
rep(i,N){
chmax(a_max,A[i]);
}
ld ok = a_max;
ld ng = 0.0;
dump(ok,ng);
/* ok と ng のどちらが大きいかわからないことを考慮 */
ll cnt = 0;
while (abs(ok - ng) > 1e-8) {
ld mid = (ok + ng) / 2;
//dump(ok,ng,mid);
if (isOK(mid)) ok = mid;
else ng = mid;
cnt ++;
if(cnt>10000){
break;
}
}
dump(ok,ng);
ll ans = (ll)ceill(ng);
dump(cnt);
bye(ans);
}
#endif
int main() {
dump("start");
func();
return 0;
}
| insert | 305 | 305 | 305 | 308 | TLE | |
p02596 | C++ | Time Limit Exceeded | // Ayushman Tripathy, IIT Roorkee, CSE-23
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define db double
#define fl float
#define endl '\n'
#define mod (ll)(1000000007)
#define mod1 (ll)998242353
#define mod2 (ll)998244353
#define PI 3.1415926535897932384626433832795
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define pob pop_back
#define Sort(v) sort(v.begin(), v.end())
#define Sortd(v) sort(v.begin(), v.end(), greater<>())
#define f(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i < n; i++)
#define rf(i, n) for (int i = n - 1; i >= 0; --i)
#define rf1(i, n) for (int i = n - 1; i >= 1; --i)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repn(i, a, b) for (int i = a; i <= b; ++i)
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
// NUMBER THEORY
// SIEVE
const int N = 1e7 + 1;
vi sieve(int n) {
vi prime;
vi pr(n + 1);
pr[0] = -1;
pr[1] = -1;
rep(i, 2, n + 1) {
if (pr[i] != -1) {
pr[i] = 1;
for (int j = 2 * i; j <= n; j += i) {
pr[j] = -1;
}
}
}
rep(i, 1, n + 1) {
if (pr[i] == 1) {
prime.pb(i);
}
}
return prime;
}
vi min_prime_factor(int n) {
vi min_pf(n + 1);
rep(i, 2, n + 1) { min_pf[i] = 0; }
min_pf[0] = 2;
min_pf[1] = -1; // Doesn't exist :(
rep(i, 2, n + 1) {
if (min_pf[i] == 0) {
for (int j = i; j <= n; j += i) {
if (min_pf[j] == 0)
min_pf[j] = i;
}
}
}
return min_pf;
}
// factorise function will return a vector consisting of all the prime factors
// and number of times they occur
vpi factorise(int n) {
vi min_pf = min_prime_factor(n);
vpi factors;
int cnt = 0, fac = 1;
while (n != 1) {
cnt = 0;
fac = min_pf[n];
while (n % fac == 0) {
cnt++;
n /= fac;
}
factors.pb(mp(fac, cnt));
}
return factors;
}
// The above gives all prime factors of n in log(n) complexity and also the
// powers of each factor in the factorisation
// EULER-TOTIENT FUNCTION
vi PHI(int n) {
vi phi(n + 1);
phi[0] = 0;
phi[1] = 1;
rep(i, 2, n + 1) { phi[i] = i; }
rep(i, 2, n + 1) {
if (phi[i] == i) {
for (int j = i; j <= n; j += i) {
phi[j] = phi[j] - phi[j] / i; // phi[i]=i(1-1/j1)(1-1/j2)(1-1/j3)...
// where j1,j2,j3.. are prime
}
}
}
return phi;
}
// nC2
ll C2(ll n) {
ll ans = max(((n * (n - 1)) / 2), (ll)0);
return ans;
}
// Square
ll sq(ll x) { return x * x; }
// Binary Exponentiation ((a^b)%m)
ll BinExp(ll a, ll b, ll m) {
ll res = 1;
a %= m;
while (b) {
if (b & 1)
res = (res * a) % m;
b >>= 1;
a = (a * a) % m;
}
return res;
}
// GCD
ll gcd(ll a, ll b) {
if (b == 0)
return a;
if (a < b)
swap(a, b);
return gcd(b, a % b);
}
ll gcdExtended(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll x1, y1;
ll g = gcdExtended(b, a % b, x1, y1);
x = y1;
y = x1 - ((ll)(a / b)) * (y1);
return g;
}
ll mod_inv(ll a, ll m) {
ll x, y;
ll g = (gcdExtended(a, m, x, y));
if (g != 1)
return -1; //{mod inv doesn't exist}
else {
ll ans = ((x % m) + m) % m; //(to make the value positive if negative x
//comes up from extended euclidean)
return ans;
}
}
// LCM
ll lcm(ll a, ll b) {
ll mul = a * b;
if (a == 0 || b == 0)
return 0;
return (mul / gcd(a, b));
}
//********************************************************************************//
// GENERAL
// PAIR SORTING
// sort pair by second values
bool sortsec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return (a.second < b.second);
}
// sort pair by first vals in descending
bool sortinrev(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return (a.first > b.first);
}
// String Hashing
ll compute_hash(string s) {
ll p = 31, m = 1e9 + 9;
ll hash = 0, po = 1;
f(i, s.length()) {
hash = (hash + (s[i] - 'a' + 1) * po) % m;
po = (po * p) % m;
}
return hash;
}
// vl h(2e6+7);//prefix hash
// vl po(2e6+7);//powers
// void compute_hash_array(string s){//same length substrings can be directly
// compared for their hash values now for equality if data set is not extremely
// large and hashes are unique
// ll p=31,m=1e9+9;
// po[0]=1;
// f1(i,n+1)po[i]=(po[i-1]*p)%m;
// h[0]=0;
// f1(i,n+1){
// h[i]=(h[i-1]+(s[i-1]-'a'+1)*po[i-1])%m;
// }
// //hash[l to r] =(((h[r+1]-h[l]+m)%m)*po[n-l])%m
// }
vl LPS(string s) {
int n = s.length();
vl lps(n);
f1(i, n) {
int j = lps[i - 1];
while (j > 0 && lps[j] != lps[i]) {
j = lps[j - 1];
}
if (s[i] == s[j])
++j;
lps[i] = j;
}
return lps;
}
//********************************************************************************//
// GRAPHS
const int V = 4e5 + 5;
vvi adj(V);
vb vis(V);
// DFS
void dfs(int s) {
vis[s] = 1;
for (auto i : adj[s]) {
if (!vis[i]) {
dfs(i);
}
}
}
// BFS
// const int V =4e5+5;
// vvi adj(V);
// vb vis(V);
// vi lvl(V);
// vi par(V);
// void bfs(int s){
// queue<int> q;
// q.push(s);
// lvl[s]=1;
// vis[s]=1;
// int v;
// while(!q.empty()){
// v=q.front();
// for(auto i:adj[v]){
// q.push(i);
// vis[i]=1;
// par[i]=v;
// lvl[i]=lvl[v]+1;
// }
// q.pop();
// }
// }
// UNION-FIND(DSU)
// const int V =4e5+5;
// vi par(V);
// vi size(V);
// void initialise(int n){
// f1(i,n+1){
// par[i]=i;
// size[i]=1;
// }
// }
// int root(int x){
// while(par[x]!=x){
// par[x]=par[par[x]];
// x=par[x];
// }
// return x;
// }
// void union_find(int a,int b){//attaches smaller tree to bigger one
// if(root(a)==root(b))return;
// if(size[root(b)]>size[root(a)])swap(a,b);//a is the bigger rooted tree
// size[root(a)]+=size[root(b)];
// par[root(b)]=root(a);
// }
//**********************************************************************************//
// For Graphs
void solve_g() {
int x, y;
int n, m;
cin >> n >> m;
f(i, m) {
cin >> x >> y;
adj[x].pb(y);
adj[y].pb(x);
}
}
void solve() {
// #ifndef ONLINE_JUDGE
// if(fopen("INPUT.txt","r"))
// {
// freopen ("INPUT.txt" , "r" , stdin);
// freopen ("OUTPUT.txt" , "w" , stdout);
// }
// #endif
int t;
cin >> t;
f(p, t) {}
}
int main() {
fast;
// solve();
ll k;
cin >> k;
if (k % 2 == 0) {
cout << -1 << endl;
} else {
k = 9 * k;
ll rem = -1;
f1(i, 9000001) {
rem = ((7 * BinExp(10, i, k) - 7) % k + k) % k;
if (rem == 0) {
cout << i << endl;
break;
}
}
if (rem != 0) {
cout << -1 << endl;
}
}
return 0;
}
| // Ayushman Tripathy, IIT Roorkee, CSE-23
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define db double
#define fl float
#define endl '\n'
#define mod (ll)(1000000007)
#define mod1 (ll)998242353
#define mod2 (ll)998244353
#define PI 3.1415926535897932384626433832795
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define pb push_back
#define pob pop_back
#define Sort(v) sort(v.begin(), v.end())
#define Sortd(v) sort(v.begin(), v.end(), greater<>())
#define f(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i < n; i++)
#define rf(i, n) for (int i = n - 1; i >= 0; --i)
#define rf1(i, n) for (int i = n - 1; i >= 1; --i)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repn(i, a, b) for (int i = a; i <= b; ++i)
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef priority_queue<int> pqi;
typedef priority_queue<ll> pql;
// NUMBER THEORY
// SIEVE
const int N = 1e7 + 1;
vi sieve(int n) {
vi prime;
vi pr(n + 1);
pr[0] = -1;
pr[1] = -1;
rep(i, 2, n + 1) {
if (pr[i] != -1) {
pr[i] = 1;
for (int j = 2 * i; j <= n; j += i) {
pr[j] = -1;
}
}
}
rep(i, 1, n + 1) {
if (pr[i] == 1) {
prime.pb(i);
}
}
return prime;
}
vi min_prime_factor(int n) {
vi min_pf(n + 1);
rep(i, 2, n + 1) { min_pf[i] = 0; }
min_pf[0] = 2;
min_pf[1] = -1; // Doesn't exist :(
rep(i, 2, n + 1) {
if (min_pf[i] == 0) {
for (int j = i; j <= n; j += i) {
if (min_pf[j] == 0)
min_pf[j] = i;
}
}
}
return min_pf;
}
// factorise function will return a vector consisting of all the prime factors
// and number of times they occur
vpi factorise(int n) {
vi min_pf = min_prime_factor(n);
vpi factors;
int cnt = 0, fac = 1;
while (n != 1) {
cnt = 0;
fac = min_pf[n];
while (n % fac == 0) {
cnt++;
n /= fac;
}
factors.pb(mp(fac, cnt));
}
return factors;
}
// The above gives all prime factors of n in log(n) complexity and also the
// powers of each factor in the factorisation
// EULER-TOTIENT FUNCTION
vi PHI(int n) {
vi phi(n + 1);
phi[0] = 0;
phi[1] = 1;
rep(i, 2, n + 1) { phi[i] = i; }
rep(i, 2, n + 1) {
if (phi[i] == i) {
for (int j = i; j <= n; j += i) {
phi[j] = phi[j] - phi[j] / i; // phi[i]=i(1-1/j1)(1-1/j2)(1-1/j3)...
// where j1,j2,j3.. are prime
}
}
}
return phi;
}
// nC2
ll C2(ll n) {
ll ans = max(((n * (n - 1)) / 2), (ll)0);
return ans;
}
// Square
ll sq(ll x) { return x * x; }
// Binary Exponentiation ((a^b)%m)
ll BinExp(ll a, ll b, ll m) {
ll res = 1;
a %= m;
while (b) {
if (b & 1)
res = (res * a) % m;
b >>= 1;
a = (a * a) % m;
}
return res;
}
// GCD
ll gcd(ll a, ll b) {
if (b == 0)
return a;
if (a < b)
swap(a, b);
return gcd(b, a % b);
}
ll gcdExtended(ll a, ll b, ll &x, ll &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
ll x1, y1;
ll g = gcdExtended(b, a % b, x1, y1);
x = y1;
y = x1 - ((ll)(a / b)) * (y1);
return g;
}
ll mod_inv(ll a, ll m) {
ll x, y;
ll g = (gcdExtended(a, m, x, y));
if (g != 1)
return -1; //{mod inv doesn't exist}
else {
ll ans = ((x % m) + m) % m; //(to make the value positive if negative x
//comes up from extended euclidean)
return ans;
}
}
// LCM
ll lcm(ll a, ll b) {
ll mul = a * b;
if (a == 0 || b == 0)
return 0;
return (mul / gcd(a, b));
}
//********************************************************************************//
// GENERAL
// PAIR SORTING
// sort pair by second values
bool sortsec(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return (a.second < b.second);
}
// sort pair by first vals in descending
bool sortinrev(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return (a.first > b.first);
}
// String Hashing
ll compute_hash(string s) {
ll p = 31, m = 1e9 + 9;
ll hash = 0, po = 1;
f(i, s.length()) {
hash = (hash + (s[i] - 'a' + 1) * po) % m;
po = (po * p) % m;
}
return hash;
}
// vl h(2e6+7);//prefix hash
// vl po(2e6+7);//powers
// void compute_hash_array(string s){//same length substrings can be directly
// compared for their hash values now for equality if data set is not extremely
// large and hashes are unique
// ll p=31,m=1e9+9;
// po[0]=1;
// f1(i,n+1)po[i]=(po[i-1]*p)%m;
// h[0]=0;
// f1(i,n+1){
// h[i]=(h[i-1]+(s[i-1]-'a'+1)*po[i-1])%m;
// }
// //hash[l to r] =(((h[r+1]-h[l]+m)%m)*po[n-l])%m
// }
vl LPS(string s) {
int n = s.length();
vl lps(n);
f1(i, n) {
int j = lps[i - 1];
while (j > 0 && lps[j] != lps[i]) {
j = lps[j - 1];
}
if (s[i] == s[j])
++j;
lps[i] = j;
}
return lps;
}
//********************************************************************************//
// GRAPHS
const int V = 4e5 + 5;
vvi adj(V);
vb vis(V);
// DFS
void dfs(int s) {
vis[s] = 1;
for (auto i : adj[s]) {
if (!vis[i]) {
dfs(i);
}
}
}
// BFS
// const int V =4e5+5;
// vvi adj(V);
// vb vis(V);
// vi lvl(V);
// vi par(V);
// void bfs(int s){
// queue<int> q;
// q.push(s);
// lvl[s]=1;
// vis[s]=1;
// int v;
// while(!q.empty()){
// v=q.front();
// for(auto i:adj[v]){
// q.push(i);
// vis[i]=1;
// par[i]=v;
// lvl[i]=lvl[v]+1;
// }
// q.pop();
// }
// }
// UNION-FIND(DSU)
// const int V =4e5+5;
// vi par(V);
// vi size(V);
// void initialise(int n){
// f1(i,n+1){
// par[i]=i;
// size[i]=1;
// }
// }
// int root(int x){
// while(par[x]!=x){
// par[x]=par[par[x]];
// x=par[x];
// }
// return x;
// }
// void union_find(int a,int b){//attaches smaller tree to bigger one
// if(root(a)==root(b))return;
// if(size[root(b)]>size[root(a)])swap(a,b);//a is the bigger rooted tree
// size[root(a)]+=size[root(b)];
// par[root(b)]=root(a);
// }
//**********************************************************************************//
// For Graphs
void solve_g() {
int x, y;
int n, m;
cin >> n >> m;
f(i, m) {
cin >> x >> y;
adj[x].pb(y);
adj[y].pb(x);
}
}
void solve() {
// #ifndef ONLINE_JUDGE
// if(fopen("INPUT.txt","r"))
// {
// freopen ("INPUT.txt" , "r" , stdin);
// freopen ("OUTPUT.txt" , "w" , stdout);
// }
// #endif
int t;
cin >> t;
f(p, t) {}
}
int main() {
fast;
// solve();
ll k;
cin >> k;
if (k % 2 == 0) {
cout << -1 << endl;
} else {
k = 9 * k;
ll rem = -1;
f1(i, 1000001) {
rem = ((7 * BinExp(10, i, k) - 7) % k + k) % k;
if (rem == 0) {
cout << i << endl;
break;
}
}
if (rem != 0) {
cout << -1 << endl;
}
}
return 0;
}
| replace | 341 | 342 | 341 | 342 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define int long long // comment it out when MLE
#define endl "\n"
// template <typename T>
// using ordered_set = tree<T, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update>;
#define gok \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
// # define m 163577857
#define mo 1000000007
#define pi acos(-1)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define REP(i, n) for (int i = 1; i <= n; i++)
const ll mod = 1e9 + 7;
// const int K = 2;
// typedef vector<vector<int> > matrix;
/*
int add(int a, int b,int mod) {
a%=mod;
b%=mod;
a += b;
if (a >= mod) a -= mod;
if(a<0)
{
a += mod;
a %= mod;
}
return a;
}
int mul(ll a, int b,int mod) {
a%=mod;
b%=mod;
a *= b;
a += mod;
return a % mod;
}
int po(int a,int b,int mod)
{
if(b==0)
return 1;
if(b%2==0)
return po(mul(a,a,mod),b/2,mod);
return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
}
ll fact[200003];
ll inv[200003];
void fact0()
{
int i,j;
fact[0]=1;
for(i=1;i<=200000;i++)
{
fact[i]=i*fact[i-1]%mod;
}
inv[0]=1;
inv[1]=1;
ll p=mod;
for (i=2; i<=200000; i++)
inv[i] = (p - (p/i) * inv[p%i] % p) % p;
for(i=2;i<=200000;i++)
{
inv[i]*=inv[i-1];
inv[i]%=mod;
}
}
int help(int a,int b)
{
// cout<<a<<" "<<b<<endl;
int an = fact[a];
//cout<<an<<endl;
an *= inv[b];
an %= mod;
an *= inv[a-b];
an %= mod;
return an;
}
/*
void random()
{
srand(time(0));
for (int i = 0; i < n; i ++)
perm[i] = i + 1;
random_shuffle(perm, perm + n);
}
int ncr(int a,int b)
{
int tt = fact[a];
tt %= mod;
tt *= inv[a-b];
tt %= mod;
tt *= inv[b];
tt %= mod;
return tt;
}
*/
signed main() {
gok
int k;
cin >> k;
if (k % 2 == 0)
cout << -1;
else {
int st = 7;
st %= k;
int cc = 1;
while (st || cc > 1e7) {
st = 10 * st + 7;
st %= k;
cc++;
}
if (cc > 1e7)
cc = -1;
cout << cc;
}
return 0;
}
| #include <bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define int long long // comment it out when MLE
#define endl "\n"
// template <typename T>
// using ordered_set = tree<T, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update>;
#define gok \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
// # define m 163577857
#define mo 1000000007
#define pi acos(-1)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define REP(i, n) for (int i = 1; i <= n; i++)
const ll mod = 1e9 + 7;
// const int K = 2;
// typedef vector<vector<int> > matrix;
/*
int add(int a, int b,int mod) {
a%=mod;
b%=mod;
a += b;
if (a >= mod) a -= mod;
if(a<0)
{
a += mod;
a %= mod;
}
return a;
}
int mul(ll a, int b,int mod) {
a%=mod;
b%=mod;
a *= b;
a += mod;
return a % mod;
}
int po(int a,int b,int mod)
{
if(b==0)
return 1;
if(b%2==0)
return po(mul(a,a,mod),b/2,mod);
return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
}
ll fact[200003];
ll inv[200003];
void fact0()
{
int i,j;
fact[0]=1;
for(i=1;i<=200000;i++)
{
fact[i]=i*fact[i-1]%mod;
}
inv[0]=1;
inv[1]=1;
ll p=mod;
for (i=2; i<=200000; i++)
inv[i] = (p - (p/i) * inv[p%i] % p) % p;
for(i=2;i<=200000;i++)
{
inv[i]*=inv[i-1];
inv[i]%=mod;
}
}
int help(int a,int b)
{
// cout<<a<<" "<<b<<endl;
int an = fact[a];
//cout<<an<<endl;
an *= inv[b];
an %= mod;
an *= inv[a-b];
an %= mod;
return an;
}
/*
void random()
{
srand(time(0));
for (int i = 0; i < n; i ++)
perm[i] = i + 1;
random_shuffle(perm, perm + n);
}
int ncr(int a,int b)
{
int tt = fact[a];
tt %= mod;
tt *= inv[a-b];
tt %= mod;
tt *= inv[b];
tt %= mod;
return tt;
}
*/
signed main() {
gok
int k;
cin >> k;
if (k % 2 == 0)
cout << -1;
else {
int st = 7;
st %= k;
int cc = 1;
while (st && cc <= 1e7) {
st = 10 * st + 7;
st %= k;
cc++;
}
if (cc > 1e7)
cc = -1;
cout << cc;
}
return 0;
}
| replace | 124 | 125 | 124 | 125 | TLE | |
p02596 | C++ | 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 (num % k == 0)
break;
num = num * 10 + 7;
num %= k;
res++;
}
} else
res = -1;
cout << res << endl;
}
int main() {
header();
solve();
return 0;
}
| #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;
}
| insert | 30 | 30 | 30 | 34 | TLE | |
p02596 | C++ | 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++;
}
}
cout << count;
return 0;
}
| #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;
}
| insert | 19 | 19 | 19 | 23 | TLE | |
p02596 | C++ | 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 <= k * k && term % k) {
term = (term * 10 % k + 7 % k) % k;
pos++;
i++;
}
if (term % k == 0)
cout << pos;
else
cout << "-1";
}
return 0;
} | #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;
} | replace | 20 | 21 | 20 | 21 | TLE | |
p02596 | C++ | Time Limit Exceeded |
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
typedef long long LL;
#define ll unsigned long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
// #define mod 1000000007
#define mod2 998244353
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define sz(v) ((ll)(v).size())
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define dbg(a) cout << #a << " --> " << (a) << "\n";
#define forn(i, n) for (ll i = 0; i < (n); ++i)
#define fornd(i, n) for (ll i = (n)-1; i >= 0; --i)
#define forab(i, a, b) for (ll i = (a); i <= (b); ++i)
#define read(a) \
ll a; \
cin >> a;
#define reads(s) \
string s; \
cin >> s;
#define readb(a, b) \
ll a, b; \
cin >> a >> b;
#define readc(a, b, c) \
ll a, b, c; \
cin >> a >> b >> c;
#define readarr(a, n) \
int a[(n) + 1] = {}; \
forab(i, 0, (n - 1)) { cin >> a[i]; }
#define readmat(a, n, m) \
int a[n + 1][m + 1] = {}; \
forab(i, 1, n) { forab(j, 1, m) cin >> a[i][j]; }
#define readv(A, n) \
vll A(n, 0); \
forn(i, n) cin >> A[i];
#define print(a) cout << a << endl;
#define printarr(a, n) \
forab(i, 1, n) cout << a[i] << " "; \
cout << endl;
#define printv(v) \
for (int i : v) \
cout << i << " "; \
cout << endl;
#define printmat(a, n, m) \
forab(i, 1, n) { \
forab(j, 1, m) cout << a[i][j] << " "; \
cout << endl; \
}
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;
void solve() {
ll k;
cin >> k;
set<ll> pq;
ll er = 7 % k;
ll i = 1;
while (er != 0) {
er = (10 * er + 7) % k;
i++;
// if(temp%k==1)
// {
// cout<<i<<endl;
// return;
// }
if (pq.count(er)) {
cout << "-1" << endl;
return;
}
}
cout << i << endl;
// cout<<"-1"<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast_io;
int T = 1;
// cin>>T;
// cin.ignore(); must be there when using getline(cin, s)
while (T--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
typedef long long LL;
#define ll unsigned long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<long long, long long>
// #define mod 1000000007
#define mod2 998244353
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define sz(v) ((ll)(v).size())
#define mp(x, y) make_pair(x, y)
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define dbg(a) cout << #a << " --> " << (a) << "\n";
#define forn(i, n) for (ll i = 0; i < (n); ++i)
#define fornd(i, n) for (ll i = (n)-1; i >= 0; --i)
#define forab(i, a, b) for (ll i = (a); i <= (b); ++i)
#define read(a) \
ll a; \
cin >> a;
#define reads(s) \
string s; \
cin >> s;
#define readb(a, b) \
ll a, b; \
cin >> a >> b;
#define readc(a, b, c) \
ll a, b, c; \
cin >> a >> b >> c;
#define readarr(a, n) \
int a[(n) + 1] = {}; \
forab(i, 0, (n - 1)) { cin >> a[i]; }
#define readmat(a, n, m) \
int a[n + 1][m + 1] = {}; \
forab(i, 1, n) { forab(j, 1, m) cin >> a[i][j]; }
#define readv(A, n) \
vll A(n, 0); \
forn(i, n) cin >> A[i];
#define print(a) cout << a << endl;
#define printarr(a, n) \
forab(i, 1, n) cout << a[i] << " "; \
cout << endl;
#define printv(v) \
for (int i : v) \
cout << i << " "; \
cout << endl;
#define printmat(a, n, m) \
forab(i, 1, n) { \
forab(j, 1, m) cout << a[i][j] << " "; \
cout << endl; \
}
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;
void solve() {
ll k;
cin >> k;
set<ll> pq;
ll er = 7 % k;
ll i = 1;
while (er != 0) {
er = (10 * er + 7) % k;
i++;
// if(temp%k==1)
// {
// cout<<i<<endl;
// return;
// }
if (pq.count(er)) {
cout << "-1" << endl;
return;
}
pq.insert(er);
}
cout << i << endl;
// cout<<"-1"<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast_io;
int T = 1;
// cin>>T;
// cin.ignore(); must be there when using getline(cin, s)
while (T--) {
solve();
}
return 0;
}
| insert | 88 | 88 | 88 | 89 | TLE | |
p02596 | C++ | 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) {
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;
}
| #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;
}
| replace | 59 | 60 | 59 | 60 | TLE | |
p02596 | C++ | Runtime Error | /* Simplicity and Goodness */
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args> void my_dbg(Arg A, Args... B) {
cout << ' ' << A;
my_dbg(B...);
}
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int maxN = 2e5 + 2;
ll me(ll x, ll n, ll m) {
ll res = 1;
x %= m;
while (n) {
if (n & 1)
res = (1LL * res * x) % m;
x = (1LL * x * x) % m;
n >>= 1;
}
return res;
}
void solve() {
ll k;
lscn(k);
ll remain = 0;
for (ll i = 0; i <= (ll)1e6 + 2; ++i) {
ll here = me(10, i, k);
here = (here * 7LL) % k;
remain += here;
if (remain % k == 0) {
lprin(i + 1);
exit(0);
}
if (here == 0) {
prin(-1);
exit(0);
}
}
assert(0);
}
int main() {
int t = 1;
// scn(t);
while (t--) {
solve();
}
return 0;
} | /* Simplicity and Goodness */
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args> void my_dbg(Arg A, Args... B) {
cout << ' ' << A;
my_dbg(B...);
}
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)
#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int maxN = 2e5 + 2;
ll me(ll x, ll n, ll m) {
ll res = 1;
x %= m;
while (n) {
if (n & 1)
res = (1LL * res * x) % m;
x = (1LL * x * x) % m;
n >>= 1;
}
return res;
}
void solve() {
ll k;
lscn(k);
ll remain = 0;
for (ll i = 0; i <= (ll)1e6 + 2; ++i) {
ll here = me(10, i, k);
here = (here * 7LL) % k;
remain += here;
if (remain % k == 0) {
lprin(i + 1);
exit(0);
}
if (here == 0) {
prin(-1);
exit(0);
}
}
prin(-1);
}
int main() {
int t = 1;
// scn(t);
while (t--) {
solve();
}
return 0;
} | replace | 74 | 75 | 74 | 75 | 0 | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long int
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define vi vector<int>
#define vvi vector<vector<int>>
#define mii map<int, int>
#define pb push_back
#define pii pair<int, int>
#define mkp make_pair
#define scan(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i]
#define print(a, n) \
for (int i = 0; i < n; i++) \
cout << a[i] << ' '
#define mem(a, v) memset(a, v, sizeof(a))
#define loop(i, a, n) for (int i = a; i < n; i++)
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define PRECISION \
std::cout.unsetf(std::ios::floatfield); \
std::cout.precision(15)
double PI = acos(-1.0);
using namespace std;
int mod = 1000000007;
int inf = INT_MAX;
int minf = INT_MIN;
/*int main()
{
int x;
cin>>x;
if(x>=30)
cout<<"Yes";
else
cout<<"No";
}*/
/*int main()
{
ll n,d;
cin>>n>>d;
int cnt=0;
while(n--)
{
ll x,y;
cin>>x>>y;
ll temp=x*x+y*y;
ll ans=ceil(sqrt(temp));
//cout<<ans<<endl;
if(ans<=d)
cnt++;
}
cout<<cnt;
}*/
int main() {
int k;
cin >> k;
if (k % 2 == 0) {
cout << "-1";
return 0;
}
int first = 7, cnt = 1;
while (k > first) {
first = first * 10 + 7;
cnt++;
}
while (first > 0) {
first = first % k;
if (first > 0) {
first = first * 10 + 7;
cnt++;
}
}
cout << cnt;
}
| #include <bits/stdc++.h>
#define ll long long int
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define vi vector<int>
#define vvi vector<vector<int>>
#define mii map<int, int>
#define pb push_back
#define pii pair<int, int>
#define mkp make_pair
#define scan(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i]
#define print(a, n) \
for (int i = 0; i < n; i++) \
cout << a[i] << ' '
#define mem(a, v) memset(a, v, sizeof(a))
#define loop(i, a, n) for (int i = a; i < n; i++)
#define FastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL)
#define PRECISION \
std::cout.unsetf(std::ios::floatfield); \
std::cout.precision(15)
double PI = acos(-1.0);
using namespace std;
int mod = 1000000007;
int inf = INT_MAX;
int minf = INT_MIN;
/*int main()
{
int x;
cin>>x;
if(x>=30)
cout<<"Yes";
else
cout<<"No";
}*/
/*int main()
{
ll n,d;
cin>>n>>d;
int cnt=0;
while(n--)
{
ll x,y;
cin>>x>>y;
ll temp=x*x+y*y;
ll ans=ceil(sqrt(temp));
//cout<<ans<<endl;
if(ans<=d)
cnt++;
}
cout<<cnt;
}*/
int main() {
int k;
cin >> k;
if (k % 2 == 0 || k % 5 == 0) {
cout << "-1";
return 0;
}
int first = 7, cnt = 1;
while (k > first) {
first = first * 10 + 7;
cnt++;
}
while (first > 0) {
first = first % k;
if (first > 0) {
first = first * 10 + 7;
cnt++;
}
}
cout << cnt;
}
| replace | 62 | 63 | 62 | 63 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <cmath>
#include <cstdint>
#include <iostream>
#include <string>
using namespace std;
int main() {
int K;
cin >> K;
if (K % 2 == 0) {
cout << -1 << endl;
return 0;
}
int64_t unit = log10(K) + 1;
int sevens = stoi(string(unit, '7'));
while (true) {
sevens %= K;
if (sevens % K == 0) {
break;
}
sevens = sevens * 10 + 7;
++unit;
}
cout << unit << endl;
return 0;
}
| #include <cmath>
#include <cstdint>
#include <iostream>
#include <string>
using namespace std;
int main() {
int K;
cin >> K;
if (K % 2 == 0) {
cout << -1 << endl;
return 0;
}
int64_t unit = log10(K) + 1;
int sevens = stoi(string(unit, '7'));
while (true) {
sevens %= K;
if (sevens % K == 0) {
break;
}
sevens = sevens * 10 + 7;
++unit;
if (unit > 10000000) {
cout << -1 << endl;
return 0;
}
}
cout << unit << endl;
return 0;
}
| insert | 23 | 23 | 23 | 28 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
#define all(v) v.begin(), v.end()
#define pb push_back
#define sz(x) (int)(x.size())
#define endl "\n"
#define isOdd(n) (n & 1)
#define pow(n, m) (ll) powl(n, m)
#define clr(x, val) memset(x, val, sizeof(x))
#define EPS 1e-7
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll k, c = 1, x = 7;
cin >> k;
if (!isOdd(k))
return cout << -1, 0;
while (x % k != 0 && c < (int)1e8) {
x = ((x * 10 % k) + 7) % k;
c++;
}
if (x % k != 0)
c = -1;
cout << c;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define all(v) v.begin(), v.end()
#define pb push_back
#define sz(x) (int)(x.size())
#define endl "\n"
#define isOdd(n) (n & 1)
#define pow(n, m) (ll) powl(n, m)
#define clr(x, val) memset(x, val, sizeof(x))
#define EPS 1e-7
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll k, c = 1, x = 7;
cin >> k;
if (!isOdd(k))
return cout << -1, 0;
while (x % k != 0 && c < (int)1e7) {
x = ((x * 10 % k) + 7) % k;
c++;
}
if (x % k != 0)
c = -1;
cout << c;
return 0;
}
| replace | 27 | 28 | 27 | 28 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define mx 100005
#define ll long long
int ar[mx];
char ch[mx];
int m, n, k, ii;
void solve() {
cin >> n;
if (n % 2 == 0) {
cout << -1 << endl;
return;
}
int cnt = 0;
ll hate = 0;
while (1) {
cnt++;
hate *= 10;
hate += 7;
hate %= n;
if (hate == 0)
break;
}
cout << cnt << endl;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int t = 1;
while (t--) {
solve();
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define mx 100005
#define ll long long
int ar[mx];
char ch[mx];
int m, n, k, ii;
void solve() {
cin >> n;
if (n % 2 == 0) {
cout << -1 << endl;
return;
}
int cnt = 0;
ll hate = 0;
while (1) {
cnt++;
hate *= 10;
hate += 7;
hate %= n;
if (hate == 0)
break;
if (cnt > 1000000) {
cout << -1 << endl;
return;
}
}
cout << cnt << endl;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
int t = 1;
while (t--) {
solve();
}
return 0;
} | insert | 26 | 26 | 26 | 30 | TLE | |
p02596 | C++ | 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;
}
printf("%d\n", number);
return 0;
} | #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;
} | insert | 14 | 14 | 14 | 18 | TLE | |
p02596 | C++ | 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;
}
cout << res << endl;
} | #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;
} | insert | 23 | 23 | 23 | 27 | TLE | |
p02596 | C++ | Time Limit Exceeded | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define ff first
#define ss second
#define pb push_back
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define lb lower_bound
#define ub upper_bound
#define D2(x) \
{ \
cerr << "[" << #x << ": "; \
for (auto it : x) \
cerr << it << " "; \
cerr << "]\n"; \
}
#define all(x) (x).begin(), (x).end()
#define mem(a) memset(a, 0, sizeof a)
#define deb(x) cout << #x << " - " << x << "\n";
#define ps(x, y) fixed << setprecision(y) << x
#define setbit(x) __builtin_popcount(x)
#define deb2(x, y) \
cerr << #x << " :: " << x << "\t" << #y << " :: " << y << "\n"
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define PI 3.141592653589793
const ll p = 5;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;
void solve() {
int k;
cin >> k;
int res = 7, mod = 9 * k;
for (int i = 1;; ++i) {
res *= 10;
res %= mod;
if (res == 7) {
cout << i;
return;
}
}
cout << "-1";
}
int main() {
IOS;
solve();
} | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define ff first
#define ss second
#define pb push_back
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define lb lower_bound
#define ub upper_bound
#define D2(x) \
{ \
cerr << "[" << #x << ": "; \
for (auto it : x) \
cerr << it << " "; \
cerr << "]\n"; \
}
#define all(x) (x).begin(), (x).end()
#define mem(a) memset(a, 0, sizeof a)
#define deb(x) cout << #x << " - " << x << "\n";
#define ps(x, y) fixed << setprecision(y) << x
#define setbit(x) __builtin_popcount(x)
#define deb2(x, y) \
cerr << #x << " :: " << x << "\t" << #y << " :: " << y << "\n"
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define PI 3.141592653589793
const ll p = 5;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;
void solve() {
int k;
cin >> k;
int res = 7, mod = 9 * k;
for (int i = 1; i <= 2000000; ++i) {
res *= 10;
res %= mod;
if (res == 7) {
cout << i;
return;
}
}
cout << "-1";
}
int main() {
IOS;
solve();
} | replace | 48 | 49 | 48 | 49 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, res, count = 1;
cin >> n;
if (n % 2 == 0 || n % 5 == 0)
count = -1;
else {
string s = "7";
stringstream(s) >> res;
while (res % n != 0) {
s += "7";
stringstream(s) >> res;
count++;
}
}
cout << count << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, res, count = 1;
cin >> n;
if (n % 2 == 0 || n % 5 == 0)
count = -1;
else {
long long m = 7 % n;
while (m != 0) {
m = (m * 10 + 7) % n;
count++;
}
}
cout << count << "\n";
return 0;
} | replace | 8 | 13 | 8 | 11 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int k;
cin >> k;
if (k % 2 == 0) {
cout << -1;
return 0;
}
if (k % 7 == 0)
k /= 7;
int p = 1;
int m = 0;
int cnt = 0;
do {
m += p;
m %= k;
p *= 10;
p %= k;
++cnt;
} while (m);
cout << cnt;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int k;
cin >> k;
if (k % 2 == 0 or k % 5 == 0) {
cout << -1;
return 0;
}
if (k % 7 == 0)
k /= 7;
int p = 1;
int m = 0;
int cnt = 0;
do {
m += p;
m %= k;
p *= 10;
p %= k;
++cnt;
} while (m);
cout << cnt;
return 0;
}
| replace | 10 | 11 | 10 | 11 | TLE | |
p02596 | C++ | Time Limit Exceeded | /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author rchalamala
*/
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.
// Competitive Coding Template
// GCC OPTIMIAZTION FLAGS
#ifndef LOCAL
#include <x86intrin.h>
#pragma GCC optimize( \
"fast-math,no-stack-protector,Ofast,omit-frame-pointer,unroll-loops,inline")
#pragma GCC option("arch=native,no-zero-upper,tune=native")
#pragma GCC target("abm,avx,avx2,bmi2,fma,mmx,popcnt,sse,sse2,sse3,sse4,ssse3")
#endif
#ifndef GENERAL_HPP
#define GENERAL_HPP
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#include <forward_list>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <mutex>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <thread>
#include <tuple>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <typename T>
using ordered_set =
__gnu_pbds::tree<T, __gnu_pbds::null_type, std::less<T>,
__gnu_pbds::rb_tree_tag,
__gnu_pbds::tree_order_statistics_node_update>;
using ui = unsigned int;
using ul = unsigned long long;
using ll = long long;
using ld = long double;
using cd = std::complex<long double>;
using pui = std::pair<unsigned int, unsigned int>;
using pii = std::pair<int, int>;
using pul = std::pair<unsigned long long, unsigned long long>;
using pll = std::pair<long long, long long>;
using pld = std::pair<long double, long double>;
using pcd = std::pair<std::complex<long double>, std::complex<long double>>;
using vui = std::vector<unsigned int>;
using vii = std::vector<int>;
using vul = std::vector<unsigned long long>;
using vll = std::vector<long long>;
using vld = std::vector<long double>;
using vcd = std::vector<std::complex<long double>>;
using vpui = std::vector<std::pair<unsigned int, unsigned int>>;
using vpii = std::vector<std::pair<int, int>>;
using vpul = std::vector<std::pair<unsigned long long, unsigned long long>>;
using vpll = std::vector<std::pair<long long, long long>>;
using vpld = std::vector<std::pair<long double, long double>>;
using vpcd = std::vector<
std::pair<std::complex<long double>, std::complex<long double>>>;
#define FOR(i, a, b) for (auto(i) = (a); (i) < (b); ++(i))
#define F0R(i, a) FOR((i), 0, (a))
#define ROF(i, a, b) for (auto(i) = (a); (i) >= (b); --(i))
#define R0F(i, a) ROF((i), (a), 0)
#define ITR(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define FSRT(set) std::sort((set).begin(), (set).end())
#define RSRT(set) std::sort((set).rbegin(), (set).rend())
#define CSRT(set, function) std::sort((set).begin(), (set).end(), (function))
#define UNIQUE(set) \
std::sort((set).begin(), (set).end()), \
(set).erase(std::unique((set).begin(), (set.end())), (a).end())
#define ALL(set) (set).begin(), (set).end()
#define RALL(set) (set).rbegin(), (set).rend()
#define mp std::make_pair
#define mt std::make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#endif
#ifndef IO_HPP
#define IO_HPP
// https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/CppIO.h
namespace std {
std::string to_string(const char &element) { return std::string(1, element); }
std::string to_string(const char *element) { return std::string(element); }
std::string to_string(const std::string &element) { return element; }
std::string to_string(const bool &element) {
#ifdef LOCAL
return element ? "true" : "false";
#else
return std::string{static_cast<char>('0' + element)};
#endif
}
template <typename T> std::string to_string(const std::complex<T> &element) {
std::stringstream convert;
convert << element;
return convert.str();
}
std::string to_string(const std::vector<bool> &elements) {
std::string convert = "{";
for (const auto &element : elements)
convert += static_cast<char>('0' + element);
return convert + "}";
}
template <std::size_t Size>
std::string to_string(const std::bitset<Size> &elements) {
std::string convert;
for (auto i = 0; i < Size; ++i)
convert += static_cast<char>('0' + elements[i]);
return convert;
}
template <typename T1, typename T2>
std::string to_string(std::pair<T1, T2> element) {
#ifdef LOCAL
return "(" + std::to_string(element.first) + ", " +
std::to_string(element.second) + ")";
#else
return std::to_string(element.ff) + " " + std::to_string(element.ss);
#endif
}
template <typename T> std::string to_string(const T &elements) {
std::string convert;
bool first = true;
#ifdef LOCAL
convert += "{";
for (const auto &element : elements) {
if (!first)
convert += ", ";
first = false;
convert += std::to_string(element);
}
convert += "}";
#else
for (const auto &element : elements) {
if (!first)
convert += " ";
first = false;
convert += std::to_string(element);
}
#endif
return convert;
}
} // namespace std
// INPUT
template <typename Arg, typename... Args>
void read(std::istream &in, Arg &first, Args &...rest);
template <typename T1, typename T2>
void read(std::istream &in, std::pair<T1, T2> &element);
template <typename T, std::size_t Size>
void read(std::istream &in, std::array<T, Size> &elements);
template <typename T> void read(std::istream &in, double &element);
template <typename T> void read(std::istream &in, long double &element);
template <typename T> void read(std::istream &in, std::complex<T> &element);
template <typename T> void read(std::istream &in, std::vector<T> &elements);
template <typename T> void read(std::istream &in, T &element);
template <typename Arg, typename... Args>
void read(std::istream &in, Arg &first, Args &...rest) {
read(in, first);
read(in, rest...);
}
template <typename T1, typename T2>
void read(std::istream &in, std::pair<T1, T2> &element) {
read(in, element.first, element.second);
}
template <typename T, std::size_t Size>
void read(std::istream &in, std::array<T, Size> &elements) {
for (auto &element : elements)
read(in, element);
}
void read(std::istream &in, double &element) {
std::string convert;
read(in, convert);
element = std::stod(convert);
}
void read(std::istream &in, long double &element) {
std::string convert;
read(in, convert);
element = std::stold(convert);
}
template <typename T> void read(std::istream &in, std::complex<T> &element) {
T first, second;
read(in, first, second);
element = std::complex<T>(first, second);
}
template <typename T> void read(std::istream &in, std::vector<T> &elements) {
for (auto &element : elements)
read(in, element);
}
template <typename T> void read(std::istream &in, T &element) { in >> element; }
// OUTPUT
template <typename Arg, typename... Args>
void print(std::ostream &out, const Arg &first, const Args &...rest);
template <typename Arg, typename... Args>
void prints(std::ostream &out, const Arg &first, const Args &...rest);
template <typename T> void print(std::ostream &out, const T &element);
void prints(std::ostream &out);
template <typename Arg, typename... Args>
void print(std::ostream &out, const Arg &first, const Args &...rest) {
print(out, first);
print(out, rest...);
}
template <typename Arg, typename... Args>
void prints(std::ostream &out, const Arg &first, const Args &...rest) {
print(out, first);
if (sizeof...(rest))
print(out, " ");
prints(out, rest...);
}
template <typename T> void print(std::ostream &out, const T &element) {
out << std::to_string(element);
}
void prints(std::ostream &out) { print(out, '\n'); }
void setIO() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
#ifdef LOCAL
std::cin.exceptions(std::ios::eofbit | std::ios::failbit | std::ios::badbit);
#endif
}
#endif
using namespace std;
constexpr long long MAXN __attribute__((unused)) =
static_cast<long long>(2 * 1e5 + 1);
constexpr long long INF __attribute__((unused)) =
static_cast<long long>(1e18 + 1);
constexpr long long MOD __attribute__((unused)) =
static_cast<long long>(1e9 + 7);
constexpr long double EPS __attribute__((unused)) =
static_cast<long double>(1e-7);
class CRepsept {
public:
void solve(std::istream &in, std::ostream &out) {
ll k;
read(in, k);
if (k % 2 == 0)
prints(out, -1);
else {
ll answer = 1, n = 7;
while (true) {
if (n % k == 0) {
prints(out, answer);
return;
}
++answer;
((n *= 10) += 7) %= k;
}
}
}
};
int main() {
setIO();
CRepsept solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
std::fflush(stdout);
return 0;
} | /**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author rchalamala
*/
/*
ID: rchalam1
LANG: C++14
TASK:
*/
// For train.usaco.org, fill the template above.
// Competitive Coding Template
// GCC OPTIMIAZTION FLAGS
#ifndef LOCAL
#include <x86intrin.h>
#pragma GCC optimize( \
"fast-math,no-stack-protector,Ofast,omit-frame-pointer,unroll-loops,inline")
#pragma GCC option("arch=native,no-zero-upper,tune=native")
#pragma GCC target("abm,avx,avx2,bmi2,fma,mmx,popcnt,sse,sse2,sse3,sse4,ssse3")
#endif
#ifndef GENERAL_HPP
#define GENERAL_HPP
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#include <forward_list>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <mutex>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <thread>
#include <tuple>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <typename T>
using ordered_set =
__gnu_pbds::tree<T, __gnu_pbds::null_type, std::less<T>,
__gnu_pbds::rb_tree_tag,
__gnu_pbds::tree_order_statistics_node_update>;
using ui = unsigned int;
using ul = unsigned long long;
using ll = long long;
using ld = long double;
using cd = std::complex<long double>;
using pui = std::pair<unsigned int, unsigned int>;
using pii = std::pair<int, int>;
using pul = std::pair<unsigned long long, unsigned long long>;
using pll = std::pair<long long, long long>;
using pld = std::pair<long double, long double>;
using pcd = std::pair<std::complex<long double>, std::complex<long double>>;
using vui = std::vector<unsigned int>;
using vii = std::vector<int>;
using vul = std::vector<unsigned long long>;
using vll = std::vector<long long>;
using vld = std::vector<long double>;
using vcd = std::vector<std::complex<long double>>;
using vpui = std::vector<std::pair<unsigned int, unsigned int>>;
using vpii = std::vector<std::pair<int, int>>;
using vpul = std::vector<std::pair<unsigned long long, unsigned long long>>;
using vpll = std::vector<std::pair<long long, long long>>;
using vpld = std::vector<std::pair<long double, long double>>;
using vpcd = std::vector<
std::pair<std::complex<long double>, std::complex<long double>>>;
#define FOR(i, a, b) for (auto(i) = (a); (i) < (b); ++(i))
#define F0R(i, a) FOR((i), 0, (a))
#define ROF(i, a, b) for (auto(i) = (a); (i) >= (b); --(i))
#define R0F(i, a) ROF((i), (a), 0)
#define ITR(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define FSRT(set) std::sort((set).begin(), (set).end())
#define RSRT(set) std::sort((set).rbegin(), (set).rend())
#define CSRT(set, function) std::sort((set).begin(), (set).end(), (function))
#define UNIQUE(set) \
std::sort((set).begin(), (set).end()), \
(set).erase(std::unique((set).begin(), (set.end())), (a).end())
#define ALL(set) (set).begin(), (set).end()
#define RALL(set) (set).rbegin(), (set).rend()
#define mp std::make_pair
#define mt std::make_tuple
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#endif
#ifndef IO_HPP
#define IO_HPP
// https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/CppIO.h
namespace std {
std::string to_string(const char &element) { return std::string(1, element); }
std::string to_string(const char *element) { return std::string(element); }
std::string to_string(const std::string &element) { return element; }
std::string to_string(const bool &element) {
#ifdef LOCAL
return element ? "true" : "false";
#else
return std::string{static_cast<char>('0' + element)};
#endif
}
template <typename T> std::string to_string(const std::complex<T> &element) {
std::stringstream convert;
convert << element;
return convert.str();
}
std::string to_string(const std::vector<bool> &elements) {
std::string convert = "{";
for (const auto &element : elements)
convert += static_cast<char>('0' + element);
return convert + "}";
}
template <std::size_t Size>
std::string to_string(const std::bitset<Size> &elements) {
std::string convert;
for (auto i = 0; i < Size; ++i)
convert += static_cast<char>('0' + elements[i]);
return convert;
}
template <typename T1, typename T2>
std::string to_string(std::pair<T1, T2> element) {
#ifdef LOCAL
return "(" + std::to_string(element.first) + ", " +
std::to_string(element.second) + ")";
#else
return std::to_string(element.ff) + " " + std::to_string(element.ss);
#endif
}
template <typename T> std::string to_string(const T &elements) {
std::string convert;
bool first = true;
#ifdef LOCAL
convert += "{";
for (const auto &element : elements) {
if (!first)
convert += ", ";
first = false;
convert += std::to_string(element);
}
convert += "}";
#else
for (const auto &element : elements) {
if (!first)
convert += " ";
first = false;
convert += std::to_string(element);
}
#endif
return convert;
}
} // namespace std
// INPUT
template <typename Arg, typename... Args>
void read(std::istream &in, Arg &first, Args &...rest);
template <typename T1, typename T2>
void read(std::istream &in, std::pair<T1, T2> &element);
template <typename T, std::size_t Size>
void read(std::istream &in, std::array<T, Size> &elements);
template <typename T> void read(std::istream &in, double &element);
template <typename T> void read(std::istream &in, long double &element);
template <typename T> void read(std::istream &in, std::complex<T> &element);
template <typename T> void read(std::istream &in, std::vector<T> &elements);
template <typename T> void read(std::istream &in, T &element);
template <typename Arg, typename... Args>
void read(std::istream &in, Arg &first, Args &...rest) {
read(in, first);
read(in, rest...);
}
template <typename T1, typename T2>
void read(std::istream &in, std::pair<T1, T2> &element) {
read(in, element.first, element.second);
}
template <typename T, std::size_t Size>
void read(std::istream &in, std::array<T, Size> &elements) {
for (auto &element : elements)
read(in, element);
}
void read(std::istream &in, double &element) {
std::string convert;
read(in, convert);
element = std::stod(convert);
}
void read(std::istream &in, long double &element) {
std::string convert;
read(in, convert);
element = std::stold(convert);
}
template <typename T> void read(std::istream &in, std::complex<T> &element) {
T first, second;
read(in, first, second);
element = std::complex<T>(first, second);
}
template <typename T> void read(std::istream &in, std::vector<T> &elements) {
for (auto &element : elements)
read(in, element);
}
template <typename T> void read(std::istream &in, T &element) { in >> element; }
// OUTPUT
template <typename Arg, typename... Args>
void print(std::ostream &out, const Arg &first, const Args &...rest);
template <typename Arg, typename... Args>
void prints(std::ostream &out, const Arg &first, const Args &...rest);
template <typename T> void print(std::ostream &out, const T &element);
void prints(std::ostream &out);
template <typename Arg, typename... Args>
void print(std::ostream &out, const Arg &first, const Args &...rest) {
print(out, first);
print(out, rest...);
}
template <typename Arg, typename... Args>
void prints(std::ostream &out, const Arg &first, const Args &...rest) {
print(out, first);
if (sizeof...(rest))
print(out, " ");
prints(out, rest...);
}
template <typename T> void print(std::ostream &out, const T &element) {
out << std::to_string(element);
}
void prints(std::ostream &out) { print(out, '\n'); }
void setIO() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
#ifdef LOCAL
std::cin.exceptions(std::ios::eofbit | std::ios::failbit | std::ios::badbit);
#endif
}
#endif
using namespace std;
constexpr long long MAXN __attribute__((unused)) =
static_cast<long long>(2 * 1e5 + 1);
constexpr long long INF __attribute__((unused)) =
static_cast<long long>(1e18 + 1);
constexpr long long MOD __attribute__((unused)) =
static_cast<long long>(1e9 + 7);
constexpr long double EPS __attribute__((unused)) =
static_cast<long double>(1e-7);
class CRepsept {
public:
void solve(std::istream &in, std::ostream &out) {
ll k;
read(in, k);
if (k % 2 == 0 || k % 5 == 0)
prints(out, -1);
else {
ll answer = 1, n = 7;
while (true) {
if (n % k == 0) {
prints(out, answer);
return;
}
++answer;
((n *= 10) += 7) %= k;
}
}
}
};
int main() {
setIO();
CRepsept solver;
std::istream &in(std::cin);
std::ostream &out(std::cout);
solver.solve(in, out);
std::fflush(stdout);
return 0;
} | replace | 323 | 324 | 323 | 324 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll k;
cin >> k;
if (k % 2 == 0) {
cout << -1 << endl;
return 0;
}
bool flag = true;
ll rem = 7;
ll ans = 1;
while (flag) {
rem = rem % k;
if (rem == 0) {
flag = false;
} else {
rem = rem * 10 + 7;
ans++;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll k;
cin >> k;
if (k % 2 == 0 || k % 5 == 0) {
cout << -1 << endl;
return 0;
}
bool flag = true;
ll rem = 7;
ll ans = 1;
while (flag) {
rem = rem % k;
if (rem == 0) {
flag = false;
} else {
rem = rem * 10 + 7;
ans++;
}
}
cout << ans << endl;
} | replace | 9 | 10 | 9 | 10 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
int n = 7 % k;
if (!(k % 2))
cout << "-1" << endl;
else {
for (int cnt = 1;;) {
if (!n) {
cout << cnt << endl;
break;
}
n = (n * 10 + 7) % k;
cnt++;
}
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
int n = 7 % k;
if (!(k % 2) || !(k % 5))
cout << "-1" << endl;
else {
for (int cnt = 1;;) {
if (!n) {
cout << cnt << endl;
break;
}
n = (n * 10 + 7) % k;
cnt++;
}
}
return 0;
} | replace | 7 | 8 | 7 | 8 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) \
cerr << #x << " is "; \
for (auto &e : (x)) \
cerr << e << ' '; \
cerr << '\n'; // vector, set
#define what_is_a(x, n) \
cerr << #x << " is "; \
for (int i = 0; i < n; i++) \
cerr << x[i] << ' '; \
cerr << '\n'; // n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) \
cerr << #x << " is "; \
for (auto &e : (x)) \
cerr << cerr_pair(e) << ' '; \
cerr << '\n'; // vector, set
#define pwhat_is_a(x, n) \
cerr << #x << " is "; \
for (int i = 0; i < n; i++) \
cerr << cerr_pair(x[i]) << ' '; \
cerr << '\n'; // n first element of array
// #define int long long
// #define pow mypow
typedef pair<int, int> pii;
const int N = 1e5 + 5;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;
int k;
int32_t main() {
IOS
// freopen("input.txt", "r", stdin);
cin >>
k;
if (k % 7 == 0)
k /= 7;
int ans = 1;
int r = 1 % k;
while (r != 0) {
r = (10 * r + 1) % k;
ans++;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) \
cerr << #x << " is "; \
for (auto &e : (x)) \
cerr << e << ' '; \
cerr << '\n'; // vector, set
#define what_is_a(x, n) \
cerr << #x << " is "; \
for (int i = 0; i < n; i++) \
cerr << x[i] << ' '; \
cerr << '\n'; // n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) \
cerr << #x << " is "; \
for (auto &e : (x)) \
cerr << cerr_pair(e) << ' '; \
cerr << '\n'; // vector, set
#define pwhat_is_a(x, n) \
cerr << #x << " is "; \
for (int i = 0; i < n; i++) \
cerr << cerr_pair(x[i]) << ' '; \
cerr << '\n'; // n first element of array
// #define int long long
// #define pow mypow
typedef pair<int, int> pii;
const int N = 1e5 + 5;
const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;
int k;
int32_t main() {
IOS
// freopen("input.txt", "r", stdin);
cin >>
k;
if (k % 7 == 0)
k /= 7;
if (__gcd(10, k) != 1)
return 0 * puts("-1");
int ans = 1;
int r = 1 % k;
while (r != 0) {
r = (10 * r + 1) % k;
ans++;
}
cout << ans << endl;
return 0;
}
| insert | 48 | 48 | 48 | 50 | TLE | |
p02596 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll k, num = 0, cnt = 0;
int main() {
while (cnt <= k) {
num = (num * 10 + 7) % k;
cnt++;
if (!num) {
cout << cnt;
return 0;
}
}
cout << "-1";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll k, num = 0, cnt = 0;
int main() {
cin >> k;
while (cnt <= k) {
num = (num * 10 + 7) % k;
cnt++;
if (!num) {
cout << cnt;
return 0;
}
}
cout << "-1";
return 0;
}
| insert | 5 | 5 | 5 | 6 | -8 | |
p02596 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
int k, i, ans = -1, tmp = 0;
for (i = 1; i <= k + 100; i++) {
tmp = tmp * 10 + 7;
tmp %= k;
if (!tmp) {
ans = i;
break;
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main() {
int k, i, ans = -1, tmp = 0;
cin >> k;
for (i = 1; i <= k + 100; i++) {
tmp = tmp * 10 + 7;
tmp %= k;
if (!tmp) {
ans = i;
break;
}
}
cout << ans;
return 0;
} | insert | 5 | 5 | 5 | 6 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main(void) {
long long K;
cin >> K;
if (K % 2 == 0)
cout << -1 << endl;
else {
long long ans = 1;
long long mod = 7 % K;
while (mod != 0) {
ans++;
mod = (mod * 10 + 7) % K;
}
cout << ans << endl;
}
return 0;
}
| #include <iostream>
using namespace std;
int main(void) {
long long K;
cin >> K;
if (K % 2 == 0)
cout << -1 << endl;
else {
long long ans = 1;
long long mod = 7 % K;
while (mod != 0) {
ans++;
mod = (mod * 10 + 7) % K;
if (ans > 1000000) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
}
return 0;
}
| insert | 15 | 15 | 15 | 19 | TLE | |
p02596 | C++ | 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 (first < 0) {
first = rem;
}
val = rem;
}
cout << i << endl;
return 0;
}
| #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;
}
| replace | 25 | 27 | 25 | 28 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define L long
#define endl "\n"
#define ___ \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
const int N = (int)1e5;
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
___
ll int n = 0,
k, x = 0;
cin >> k;
if (k % 2 == 0) {
cout << -1;
return 0;
}
while (1) {
n = ((n * 10) + 7) % k;
x++;
if (n == 0)
break;
else if (x == (int)2e8) {
cout << -1;
return 0;
}
}
cout << x;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define L long
#define endl "\n"
#define ___ \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
const int N = (int)1e5;
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
___
ll int n = 0,
k, x = 0;
cin >> k;
if (k % 2 == 0) {
cout << -1;
return 0;
}
while (1) {
n = ((n * 10) + 7) % k;
x++;
if (n == 0)
break;
else if (x == (int)1e8 + (int)1e7) {
cout << -1;
return 0;
}
}
cout << x;
return 0;
} | replace | 31 | 32 | 31 | 32 | TLE | |
p02596 | C++ | Time Limit Exceeded | /*
Author : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com
" when you are not practicing someone else is ,
and the day u meet them u will lose "
*/
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define MAX 200050
#define ll long long
#define ld long double
#define lli long long int
#define pb push_back
#define INF 1000000000000
#define mod 1000000007
// trignometric function always give value in Radians only
#define PI acos(-1) // 3.1415926535897932384626433832795028
#define dsin(degree) sin(degree *(PI / 180.0))
#define dcos(degree) cos(degree *(PI / 180.0))
#define dtan(degree) tan(degree *(PI / 180.0))
#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define loop(i, n) for (lli i = 0; i < n; i++)
#define FOR(i, a, b) for (lli i = a; i < b; i += 1)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(x) int(x.size())
#define F first
#define S second
#define mii map<lli, lli>
#define mci map<char, lli>
#define vi vector<lli>
#define vbool vector<bool>
#define seti set<lli>
#define pii pair<lli, lli>
#define pcc pair<char, char>
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) (a / gcd(a, b)) * b
#define abs(x) ((x < 0) ? -(x) : x)
#define endl '\n'
template <typename T> void print(T x) { cout << x << endl; }
template <typename T1, typename T2> void print2(T1 x, T2 y) {
cout << x << " " << y << endl;
}
template <typename T1, typename T2, typename T3> void print3(T1 x, T2 y, T3 z) {
cout << x << " " << y << " " << z << endl;
}
#define scanarr(a, n) \
for (lli i = 0; i < n; i++) \
cin >> a[i];
#define scanvec(a, n) \
for (lli i = 0; i < n; i++) { \
lli x; \
cin >> x; \
a.pb(x); \
}
#define printarr(a, n) \
for (lli i = 0; i < n; i++) \
cout << a[i] << " "; \
cout << endl;
#define printvec(vec) \
for (auto xt : vec) \
cout << xt << " "; \
cout << "\n";
#define FD(N) fixed << setprecision(N)
#define deb(x) cout << #x << " " << x << endl;
// chandan1,2
void chandan1() {
int y = 1;
return;
}
void chandan2() {
loop(i, 10) { lli x = 1; }
return (chandan1());
}
int main() {
fastio lli t = 1;
// cin>>t;
chandan2();
while (t--) {
lli k;
cin >> k;
if (k % 2 == 0)
print(-1);
else {
lli ans = 0;
lli cnt = 0;
while (true) {
ans = ans * 10 + 7;
ans %= k;
cnt++;
if (ans == 0)
break;
}
print(cnt);
}
}
return 0;
}
| /*
Author : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com
" when you are not practicing someone else is ,
and the day u meet them u will lose "
*/
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define MAX 200050
#define ll long long
#define ld long double
#define lli long long int
#define pb push_back
#define INF 1000000000000
#define mod 1000000007
// trignometric function always give value in Radians only
#define PI acos(-1) // 3.1415926535897932384626433832795028
#define dsin(degree) sin(degree *(PI / 180.0))
#define dcos(degree) cos(degree *(PI / 180.0))
#define dtan(degree) tan(degree *(PI / 180.0))
#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define loop(i, n) for (lli i = 0; i < n; i++)
#define FOR(i, a, b) for (lli i = a; i < b; i += 1)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(x) int(x.size())
#define F first
#define S second
#define mii map<lli, lli>
#define mci map<char, lli>
#define vi vector<lli>
#define vbool vector<bool>
#define seti set<lli>
#define pii pair<lli, lli>
#define pcc pair<char, char>
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) (a / gcd(a, b)) * b
#define abs(x) ((x < 0) ? -(x) : x)
#define endl '\n'
template <typename T> void print(T x) { cout << x << endl; }
template <typename T1, typename T2> void print2(T1 x, T2 y) {
cout << x << " " << y << endl;
}
template <typename T1, typename T2, typename T3> void print3(T1 x, T2 y, T3 z) {
cout << x << " " << y << " " << z << endl;
}
#define scanarr(a, n) \
for (lli i = 0; i < n; i++) \
cin >> a[i];
#define scanvec(a, n) \
for (lli i = 0; i < n; i++) { \
lli x; \
cin >> x; \
a.pb(x); \
}
#define printarr(a, n) \
for (lli i = 0; i < n; i++) \
cout << a[i] << " "; \
cout << endl;
#define printvec(vec) \
for (auto xt : vec) \
cout << xt << " "; \
cout << "\n";
#define FD(N) fixed << setprecision(N)
#define deb(x) cout << #x << " " << x << endl;
// chandan1,2
void chandan1() {
int y = 1;
return;
}
void chandan2() {
loop(i, 10) { lli x = 1; }
return (chandan1());
}
int main() {
fastio lli t = 1;
// cin>>t;
chandan2();
while (t--) {
lli k;
cin >> k;
if (k % 2 == 0 or k % 5 == 0)
print(-1);
else {
lli ans = 0;
lli cnt = 0;
while (true) {
ans = ans * 10 + 7;
ans %= k;
cnt++;
if (ans == 0)
break;
}
print(cnt);
}
}
return 0;
}
| replace | 112 | 113 | 112 | 113 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
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;
}
ll k;
ll mod_pow(ll x, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1) {
res = res * x % (k * 9);
}
x = x * x % (k * 9);
n >>= 1;
}
return res;
}
int main() {
cin >> k;
for (int i = 1; i <= 9 * k; i++) {
// cout << i << endl;
if (7 * ((mod_pow(10, i) - 1)) % (9 * k) == 0) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
const ll LINF = 1LL << 60;
const int INF = 1 << 30;
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;
}
ll k;
ll mod_pow(ll x, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1) {
res = res * x % (k * 9);
}
x = x * x % (k * 9);
n >>= 1;
}
return res;
}
int main() {
cin >> k;
for (int i = 1; i <= k; i++) {
// cout << i << endl;
if (7 * ((mod_pow(10, i) - 1)) % (9 * k) == 0) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
} | replace | 42 | 43 | 42 | 43 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define pb push_back
#define fori(j, n) for (int i = j; i < n; i++)
#define forj(i, n) for (int j = i; j < n; j++)
#define fork(i, n) for (int k = i; k < n; k++)
#define ppb pop_back()
#define umap unordered_map
#define uset unordered_set
#define lli long long int
using namespace std;
void solve() {
lli k;
cin >> k;
if (k % 2 == 0) {
cout << -1;
return;
}
lli ans = 0;
int cnt = 0;
while (1) {
cnt++;
ans = (ans * 10 + 7) % k;
if (ans == 0)
break;
}
cout << cnt;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// int t;cin>>t;
// while(t--)
// {
solve();
// cout<<endl;
// }
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define fori(j, n) for (int i = j; i < n; i++)
#define forj(i, n) for (int j = i; j < n; j++)
#define fork(i, n) for (int k = i; k < n; k++)
#define ppb pop_back()
#define umap unordered_map
#define uset unordered_set
#define lli long long int
using namespace std;
void solve() {
lli k;
cin >> k;
if (k % 2 == 0 or k % 5 == 0) {
cout << -1;
return;
}
lli ans = 0;
int cnt = 0;
while (1) {
cnt++;
ans = (ans * 10 + 7) % k;
if (ans == 0)
break;
}
cout << cnt;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// int t;cin>>t;
// while(t--)
// {
solve();
// cout<<endl;
// }
return 0;
} | replace | 15 | 16 | 15 | 16 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
#define IOS \
{ \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0); \
}
#define ll long long
ll powermod(ll x, ll ex, ll md) {
ll ans = 1ll;
while (ex > 0) {
if (ex & 1ll)
ans = (ans * x) % md;
ex >>= 1ll;
x = (x * x) % md;
}
return ans;
}
int main() {
IOS;
ll n;
cin >> n;
// vector<ll> factor;
// for(ll i=1;i*i<=n;++i){
// if(n%i==0){
// ll div1=i,div2=n/i;
// factor.push_back(div1);
// if(div1 != div2) factor.push_back(div2);
// }
// }
// for(ll i=0;i<(int)(factor.size());i++) cout << factor[i] <<" ";
ll ans = -1;
if (n == 7) {
cout << 1 << "\n";
return 0;
} else if (n % 2 == 0) {
cout << -1 << "\n";
return 0;
}
n *= 9;
for (ll i = 1; i <= 1e7; i++) {
ll b = 3;
ll a = powermod(10, i, n);
a %= n;
(a) = (a - 1 + n) % n;
a = ((a % n) * 7) % n;
if (a == 0) {
ans = i;
break;
}
}
if (ans != -1)
cout << ans << "\n";
else
cout << -1 << "\n";
}
| #include "bits/stdc++.h"
using namespace std;
#define IOS \
{ \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0); \
}
#define ll long long
ll powermod(ll x, ll ex, ll md) {
ll ans = 1ll;
while (ex > 0) {
if (ex & 1ll)
ans = (ans * x) % md;
ex >>= 1ll;
x = (x * x) % md;
}
return ans;
}
int main() {
IOS;
ll n;
cin >> n;
// vector<ll> factor;
// for(ll i=1;i*i<=n;++i){
// if(n%i==0){
// ll div1=i,div2=n/i;
// factor.push_back(div1);
// if(div1 != div2) factor.push_back(div2);
// }
// }
// for(ll i=0;i<(int)(factor.size());i++) cout << factor[i] <<" ";
ll ans = -1;
if (n == 7) {
cout << 1 << "\n";
return 0;
} else if (n % 2 == 0) {
cout << -1 << "\n";
return 0;
}
n *= 9;
for (ll i = 1; i <= 1e6; i++) {
ll b = 3;
ll a = powermod(10, i, n);
a %= n;
(a) = (a - 1 + n) % n;
a = ((a % n) * 7) % n;
if (a == 0) {
ans = i;
break;
}
}
if (ans != -1)
cout << ans << "\n";
else
cout << -1 << "\n";
}
| replace | 47 | 48 | 47 | 48 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
// 入力
cin >> K;
int ans = -1;
int o;
o = K / 10;
if (K % 2 != 0 and K % 5 != 0) {
for (int i = o; i >= 0; i++) {
int seven = 0;
for (int j = 0; j <= i; j++) {
seven = seven + 7 * pow(10, j);
}
if (seven % K == 0) {
ans = i + 1;
break;
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
// 入力
cin >> K;
int ans = -1;
int seven = 0;
for (int i = 1; i <= 1000001; i++) {
seven = 10 * seven % K + 7;
if (seven % K == 0) {
ans = i;
break;
}
}
cout << ans << endl;
}
| replace | 8 | 20 | 8 | 14 | TLE | |
p02596 | C++ | Runtime Error | /*
Author:loceaner
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define int long long
using namespace std;
const int A = 1e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
inline int read() {
char c = getchar();
int x = 0, f = 1;
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = x * 10 + (c ^ 48);
return x * f;
}
int k, a[A];
signed main() {
k = read();
for (int i = 1; i <= k; i++) {
a[i] = a[i - 1] * 10 + 7;
a[i] %= k;
if (a[i] == 0) {
cout << i << '\n';
return 0;
}
}
cout << -1 << '\n';
} | /*
Author:loceaner
*/
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define int long long
using namespace std;
const int A = 1e6 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
inline int read() {
char c = getchar();
int x = 0, f = 1;
for (; !isdigit(c); c = getchar())
if (c == '-')
f = -1;
for (; isdigit(c); c = getchar())
x = x * 10 + (c ^ 48);
return x * f;
}
int k, a[A];
signed main() {
k = read();
for (int i = 1; i <= k; i++) {
a[i] = a[i - 1] * 10 + 7;
a[i] %= k;
if (a[i] == 0) {
cout << i << '\n';
return 0;
}
}
cout << -1 << '\n';
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02596 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
int k;
cin >> k;
bool flag = false;
ll l = (k % 7 == 0) ? 9 * k / l : 9 * k;
ll n = 1;
for (ll i = 1; i <= l; i++) {
n = (n % l) * 10 % l;
if (n == 1) {
cout << i << endl;
flag = true;
break;
}
}
if (!flag)
cout << -1 << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main() {
int k;
cin >> k;
bool flag = false;
ll l = (k % 7 == 0) ? 9 * k / 7 : 9 * k;
ll n = 1;
for (ll i = 1; i <= l; i++) {
n = (n % l) * 10 % l;
if (n == 1) {
cout << i << endl;
flag = true;
break;
}
}
if (!flag)
cout << -1 << endl;
return 0;
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02596 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll k;
vector<int> v = vector<int>(k, -1);
v[0] = 0;
ll a = 0;
ll idx = 1;
while (true) {
a = a * 10 + 7;
a %= k;
if (v[a] != -1) {
cout << idx - v[a] << endl;
return 0;
} else {
v[a] = idx;
}
idx++;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll k;
cin >> k;
if (k % 2 == 0 || k % 5 == 0) {
cout << -1 << endl;
return 0;
}
vector<int> v = vector<int>(k, -1);
v[0] = 0;
ll a = 0;
ll idx = 1;
while (true) {
a = a * 10 + 7;
a %= k;
if (v[a] != -1) {
cout << idx - v[a] << endl;
return 0;
} else {
v[a] = idx;
}
idx++;
}
return 0;
}
| insert | 7 | 7 | 7 | 12 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
ll x;
bool chk(int x) {
if (x == 0)
return 0;
while (x) {
if (x % 10 != 1)
return 0;
x /= 10;
}
return 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> x;
int cnt = 0;
ll tmp = 0;
if (x % 7 == 0)
x /= 7;
while (1) {
int y = ((11 - tmp % 10) % 10);
if (chk(tmp)) {
while (tmp)
tmp /= 10, cnt++;
cout << cnt;
return 0;
}
bool pos = 0;
for (int i = 0; i < 10; i++)
if (i * x % 10 == y) {
tmp += x * i;
tmp /= 10;
pos = 1;
break;
}
if (pos)
cnt++;
else {
cout << -1;
return 0;
}
}
}
| #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 5;
ll x;
bool chk(int x) {
if (x == 0)
return 0;
while (x) {
if (x % 10 != 1)
return 0;
x /= 10;
}
return 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> x;
int cnt = 0;
ll tmp = 0;
if (x % 7 == 0)
x /= 7;
if (x == 1) {
cout << 1;
return 0;
}
while (1) {
int y = ((11 - tmp % 10) % 10);
if (chk(tmp)) {
while (tmp)
tmp /= 10, cnt++;
cout << cnt;
return 0;
}
bool pos = 0;
for (int i = 0; i < 10; i++)
if (i * x % 10 == y) {
tmp += x * i;
tmp /= 10;
pos = 1;
break;
}
if (pos)
cnt++;
else {
cout << -1;
return 0;
}
}
}
| insert | 38 | 38 | 38 | 42 | TLE | |
p02596 | C++ | 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 < 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;
} | #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;
} | replace | 11 | 12 | 11 | 12 | TLE | |
p02596 | C++ | 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>;
int main() {
ll K;
cin >> K;
if (K % 2 == 0) {
cout << -1 << endl;
return 0;
}
ll ans = 1;
ll x = 7;
x %= K;
while (x) {
ans++;
x = x * 10 + 7;
x %= K;
}
cout << ans << endl;
return 0;
} | #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>;
int main() {
ll K;
cin >> K;
if (K % 2 == 0 || K % 5 == 0) {
cout << -1 << endl;
return 0;
}
ll ans = 1;
ll x = 7;
x %= K;
while (x) {
ans++;
x = x * 10 + 7;
x %= K;
}
cout << ans << endl;
return 0;
} | replace | 9 | 10 | 9 | 10 | TLE | |
p02596 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define dub long double
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ROF(i, a, b) for (int i = (a); i > (b); --i)
#define CASET \
int _T; \
cin >> _T; \
FOR(caset, 1, _T + 1)
#define pii pair<int, int>
#define t3i tuple<int, int, int>
#define mii map<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define vpii vector<pii>
#define vt3i vector<t3i>
#define vvpii vector<vpii>
#define sq(x) (x) * (x)
#define inv(x) powa(x, MOD - 2)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SIZE(x) (signed)(x).size()
#define SUM(x) accumulate(ALL(x), 0LL)
long long INF = 1LL << 60;
long long MOD = 1e9 + 7;
namespace output {
void pr(short x) { cout << x; }
void pr(signed x) { cout << x; }
void pr(long x) { cout << x; }
void pr(long long x) { cout << x; }
void pr(unsigned short x) { cout << x; }
void pr(unsigned x) { cout << x; }
void pr(unsigned long x) { cout << x; }
void pr(unsigned long long x) { cout << x; }
void pr(float x) { cout << x; }
void pr(double x) { cout << x; }
void pr(long double x) { cout << x; }
void pr(char x) { cout << x; }
void pr(const char *x) { cout << x; }
void pr(const string &x) { cout << x; }
void pr(bool x) { cout << x; }
template <size_t sz> void pr(const bitset<sz> &x) { cout << x; }
template <class T> void pr(const complex<T> &x) { cout << x; }
template <class T1, class T2> void pr(const pair<T1, T2> &x);
template <class T1, class T2, class T3> void pr(const tuple<T1, T2, T3> &x);
template <class T> void pr(const T &x);
template <class T, class... Ts> void pr(const T &t, const Ts &...ts) {
pr(t);
pr(ts...);
}
template <class T1, class T2> void pr(const pair<T1, T2> &x) {
pr("(", x.first, ", ", x.second, ")");
}
template <class T1, class T2, class T3> void pr(const tuple<T1, T2, T3> &x) {
pr("(", get<0>(x), ", ", get<1>(x), ", ", get<2>(x), ")");
}
template <class T> void pr(const T &x) {
pr("["); // const iterator needed for vector<bool>
bool fst = 1;
for (const auto &a : x)
pr(!fst ? ", " : "", a), fst = 0;
pr("]");
}
void print() { pr("\n"); } // print w/ spaces
template <class T, class... Ts> void print(const T &t, const Ts &...ts) {
pr(t);
if (sizeof...(ts))
pr(" ");
print(ts...);
}
} // namespace output
using namespace output;
template <typename T = int> vector<T> create(size_t n) { return vector<T>(n); }
template <typename T, typename... Args> auto create(size_t n, Args... args) {
return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
template <class T1, class T2>
istream &operator>>(istream &is, pair<T1, T2> &x) {
is >> x.first >> x.second;
return is;
}
template <class T1, class T2, class T3>
istream &operator>>(istream &is, tuple<T1, T2, T3> &x) {
is >> get<0>(x) >> get<1>(x) >> get<2>(x);
return is;
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v)
is >> x;
return is;
}
int powa(int base, int exp) {
int res = 1;
while (exp) {
if (exp & 1)
res = res * base % MOD;
base = base * base % MOD;
exp >>= 1;
}
return res;
}
bool mini(int &a, int b) { return b < a ? a = b, 1 : 0; }
bool maxi(int &a, int b) { return b > a ? a = b, 1 : 0; }
const int B = 700;
bool cmp(t3i a, t3i b) {
int aa = get<0>(a) / B;
int bb = get<0>(b) / B;
if (aa < bb)
return true;
if (aa > bb)
return false;
return get<1>(a) < get<1>(b);
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
MOD = n;
int res = 1;
int k = 7 % n;
while (k) {
k = (k + 7 * powa(10, res) % n) % n;
++res;
}
print(res);
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define dub long double
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ROF(i, a, b) for (int i = (a); i > (b); --i)
#define CASET \
int _T; \
cin >> _T; \
FOR(caset, 1, _T + 1)
#define pii pair<int, int>
#define t3i tuple<int, int, int>
#define mii map<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define vpii vector<pii>
#define vt3i vector<t3i>
#define vvpii vector<vpii>
#define sq(x) (x) * (x)
#define inv(x) powa(x, MOD - 2)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SIZE(x) (signed)(x).size()
#define SUM(x) accumulate(ALL(x), 0LL)
long long INF = 1LL << 60;
long long MOD = 1e9 + 7;
namespace output {
void pr(short x) { cout << x; }
void pr(signed x) { cout << x; }
void pr(long x) { cout << x; }
void pr(long long x) { cout << x; }
void pr(unsigned short x) { cout << x; }
void pr(unsigned x) { cout << x; }
void pr(unsigned long x) { cout << x; }
void pr(unsigned long long x) { cout << x; }
void pr(float x) { cout << x; }
void pr(double x) { cout << x; }
void pr(long double x) { cout << x; }
void pr(char x) { cout << x; }
void pr(const char *x) { cout << x; }
void pr(const string &x) { cout << x; }
void pr(bool x) { cout << x; }
template <size_t sz> void pr(const bitset<sz> &x) { cout << x; }
template <class T> void pr(const complex<T> &x) { cout << x; }
template <class T1, class T2> void pr(const pair<T1, T2> &x);
template <class T1, class T2, class T3> void pr(const tuple<T1, T2, T3> &x);
template <class T> void pr(const T &x);
template <class T, class... Ts> void pr(const T &t, const Ts &...ts) {
pr(t);
pr(ts...);
}
template <class T1, class T2> void pr(const pair<T1, T2> &x) {
pr("(", x.first, ", ", x.second, ")");
}
template <class T1, class T2, class T3> void pr(const tuple<T1, T2, T3> &x) {
pr("(", get<0>(x), ", ", get<1>(x), ", ", get<2>(x), ")");
}
template <class T> void pr(const T &x) {
pr("["); // const iterator needed for vector<bool>
bool fst = 1;
for (const auto &a : x)
pr(!fst ? ", " : "", a), fst = 0;
pr("]");
}
void print() { pr("\n"); } // print w/ spaces
template <class T, class... Ts> void print(const T &t, const Ts &...ts) {
pr(t);
if (sizeof...(ts))
pr(" ");
print(ts...);
}
} // namespace output
using namespace output;
template <typename T = int> vector<T> create(size_t n) { return vector<T>(n); }
template <typename T, typename... Args> auto create(size_t n, Args... args) {
return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
template <class T1, class T2>
istream &operator>>(istream &is, pair<T1, T2> &x) {
is >> x.first >> x.second;
return is;
}
template <class T1, class T2, class T3>
istream &operator>>(istream &is, tuple<T1, T2, T3> &x) {
is >> get<0>(x) >> get<1>(x) >> get<2>(x);
return is;
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v)
is >> x;
return is;
}
int powa(int base, int exp) {
int res = 1;
while (exp) {
if (exp & 1)
res = res * base % MOD;
base = base * base % MOD;
exp >>= 1;
}
return res;
}
bool mini(int &a, int b) { return b < a ? a = b, 1 : 0; }
bool maxi(int &a, int b) { return b > a ? a = b, 1 : 0; }
const int B = 700;
bool cmp(t3i a, t3i b) {
int aa = get<0>(a) / B;
int bb = get<0>(b) / B;
if (aa < bb)
return true;
if (aa > bb)
return false;
return get<1>(a) < get<1>(b);
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
if (n % 2 == 0 || n % 5 == 0) {
print(-1);
exit(0);
}
MOD = n;
int res = 1;
int k = 7 % n;
while (k) {
k = (k + 7 * powa(10, res) % n) % n;
++res;
}
print(res);
} | insert | 134 | 134 | 134 | 139 | TLE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.