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: Time Limit Exceeded)

#include<bits/stdc++.h>
 
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(vector<vector<T>> x){cerr<<"\n{"; int f=x.size();for(int i=0;i<f;i++){cerr<<"("; int g=x[i].size(); for(auto j:x[i]){cerr<<j; (--g!=0)?cerr<<",":cerr<<"";}cerr<<")\n";}cerr<<"}";}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void __print(vector<bool> x){cerr<<"{";int f=x.size();for(auto i:x){cerr<<i;(--f !=0)?cerr<<",":cerr<<"";}cerr<<"}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
 
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = [", _print(x)
#else
#define trace(x...)
#endif
 
template<typename... T>
void read(T&... args) {
    ((cin >> args), ...);
}
 
template<typename... T>
void writ(T&&... args) {
    ((cout << args << " "), ...);
}
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define INF (ll)1e18
#define IINF (int)1e9
#define EPS 1e-9
/*
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    In the blazing sun I saw you
    In the shadows hiding from yourself
    When the lights are on I know you
    See you're grey from all the lies you tell 
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k; cin>>k;
    if(k&1){
        ll x=0; //This is mostly assumption based but I still need to prove it
        bool flag=true;
        ll ans=0;
        while(flag){//there is meant to be some condition here I don't know what
            x=((x*10)+7)%k;
            ans++;
            if(!x) flag=false;
        }
        cout<<ans<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}