Skip to content

Commit 080ab65

Browse files
Add files via upload
1 parent e5b63e5 commit 080ab65

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#pragma GCC optimize("Ofast")
2+
#pragma GCC optimize("unroll-loops")
3+
#include <bits/stdc++.h>
4+
using namespace std;
5+
6+
typedef long long ll;
7+
#define fast_cin() \
8+
ios_base::sync_with_stdio(false); \
9+
cin.tie(NULL); \
10+
cout.tie(NULL);
11+
12+
ll best;
13+
void can(ll n, ll j) {
14+
for (ll i = 0; i <= 6; i++) {
15+
ll x = n + i * j;
16+
while (x) {
17+
if (x % 10 == 7) {
18+
best = min(best, i);
19+
return;
20+
};
21+
x /= 10;
22+
}
23+
}
24+
}
25+
26+
int main() {
27+
fast_cin();
28+
int tc;
29+
cin >> tc;
30+
while (tc--) {
31+
ll n;
32+
cin >> n;
33+
best = 7;
34+
35+
can(n, 9LL);
36+
can(n, 99LL);
37+
can(n, 999LL);
38+
can(n, 9999LL);
39+
can(n, 99999LL);
40+
can(n, 999999LL);
41+
can(n, 9999999LL);
42+
can(n, 99999999LL);
43+
can(n, 999999999LL);
44+
cout << best << endl;
45+
}
46+
47+
return 0;
48+
}

0 commit comments

Comments
 (0)