fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. const int MOD = 1e9 + 7;
  7.  
  8. void solve(){
  9. int n;
  10. cin >> n;
  11. int m = to_string(n).size();
  12. int ans = INT_MAX;
  13. int len = 1;
  14.  
  15. string h = to_string(n);
  16.  
  17. for(auto x: h){
  18. if(x == '7'){
  19. cout << 0 << "\n";
  20. return;
  21. }
  22. }
  23. for(int i = 0; i <= 2 * m; i++){
  24. ll tmp = n;
  25. for(int j = 0; j < 500; j++){
  26. ll g = pow(10, len);
  27. g--;
  28. tmp += g;
  29. string h = to_string(tmp);
  30. if(h.size() >= 17)break;
  31. bool done = false;
  32. for(auto x: h){
  33. if(x == '7'){
  34. done = true;
  35. ans = min(ans, j + 1);
  36. break;
  37. }
  38. }
  39. if(done){
  40. break;
  41. }
  42.  
  43. }
  44. len++;
  45.  
  46. }
  47. cout << ans << "\n";
  48. }
  49.  
  50. int main(){
  51. ios_base::sync_with_stdio(false);
  52. cin.tie(nullptr);
  53.  
  54. int t = 1;
  55. cin >> t;
  56.  
  57. for(int i = 1; i <= t; i++){
  58. solve();
  59. }
  60. return 0;
  61. }
Success #stdin #stdout 0s 5284KB
stdin
16
51
60
61
777
12345689
1000000000
2002
3001
977
989898986
80
800001
96
70
15
90
stdout
3
2
1
0
1
3
5
4
0
7
1
2
7
0
7
3