Problem:
Score : 300 points

Problem Statement

Takahashi loves the number 7 and multiples of K.

Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.)

If the sequence contains no multiples of K, print -1 instead.

Constraints

1 \leq K \leq 10^6

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print 4.)

Sample Input 1

101

Sample Output 1

4

None of 7, 77, and 777 is a multiple of 101, but 7777 is.

Sample Input 2

2

Sample Output 2

-1

All elements in the sequence are odd numbers; there are no multiples of 2.

Sample Input 3

999983

Sample Output 3

999982

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

/**
 * The man who codes no bugs
 * McCheng is the man studying Maths in CUHK with IQ200
 * @author McCheng
 */

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


const double PI = acos(-1.0);

using namespace std;

template<typename T>
bool isPrime(T n) {
    if (n <= 1) return false;
    if (n <= 3) return true;
    if (n % 2 == 0 || n % 3 == 0) return false;
    for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;
}

template<typename T>
vector<T> allFactors(T n) {
    vector<T> res;
    vector<T> tmp;
    T i = 1;
    while (i*i <= n) {
        if (n % i == 0) {
            res.push_back(i);
            if (n/i != i) tmp.push_back(n/i);
        }
        i++;
    }
    reverse(tmp.begin(), tmp.end());
    for (T j : tmp) {
        res.push_back(j);
    }
    return res;
}

template<typename T>
vector<T> factorization(T n) {
    vector<T> factors;
    for (int d : {2,3,5}) {
        while (n%d == 0) {
            factors.push_back(d);
             n /= d;
        }
    }
    static array<int, 8> increments = {4, 2, 4, 2, 4, 6, 2, 6};
    int i = 0;
    for (long long d = 7; d * d <= n; d += increments[i++]) {
        while (n % d == 0) {
            factors.push_back(d);
            n /= d;
        }
        if (i == 8) i = 0;
    }
    if (n > 1) factors.push_back(n);
    return factors;
}

template<typename T>
bool isPowerOf2(T x) { return x && (!(x & (x - 1))); }

template<typename T>
T factorial(T n) {
    T f = 1;
    for (T i = 2; i <= n; i++) f *= i;
    return f;
}

template<typename T>
T gcd(T a, T b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

template<typename T>
T extgcd(T a, T b, T &x, T &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    T x1, y1;
    T d = extgcd(b, a % b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}

template<typename T>
T mod_inverse(T a, T mod){
    T x, y;
    extgcd(a, mod, x, y);
    return (mod + x % mod) % mod;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

template<typename T>
T digitSum(T number, T mod = 10) {
    int ans = 0;
    while (number) {
        ans += number % mod;
        number /= mod;
    }
    return ans;
}

class CRepsept {
public:
    static constexpr int kStressCount = 0;
    static void generateTest(ostream& test) {}
	void solve(istream& cin, ostream& cout) {
int n;cin>>n;

if (n%2==0 || n%5==0){
    cout<<-1<<"\n";
    return;
}
        int ans=1;
if (n%7==0){
    n/=7;
}
if (n==1) {
            cout<<1;
            return;
        }
        long long t=1;
while (t!=0){
    t=(10*t+1)%n;
    ans++;
}
        cout<<ans;
	}
};

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream &in(cin);
    ostream &out(cout);
    out << fixed;
    out.precision(20);
    CRepsept solver;
    solver.solve(in, out);
}