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# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramC a = new ProgramC();
            a.main();//実行する

        }

    }
    //ABC170
    class ProgramA
    {
        public void main()
        {
            //入力
            int x = int.Parse(Console.ReadLine());


            if (x >= 30)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");

        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力
            
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long d = long.Parse(s[1]);

            long count = 0;
            for(int i = 0; i < n;i++)
            {
                string[] t = Console.ReadLine().Split(' ');
                long x = long.Parse(t[0]);
                long y = long.Parse(t[1]);
                if (x * x + y * y <= d * d)
                    count++;
            }

            Console.WriteLine(count);

        }
    }

    class ProgramC
    {
        public void main()
        {

            //入力
            int k = int.Parse(Console.ReadLine());

            if(k % 2 == 0)
            {
                Console.WriteLine("-1");
                return;
            }

            if (7 % k == 0)
            {
                Console.WriteLine("1");
                return;
            }


            int flag = 0;
            long num = 7;
            long count = 1;

            while(flag == 0)
            {
                count++;
                num *= 10;
                num += 7;
                num %= k;
                if (num == 0)
                    flag = 1;
                if (count >= 10000000)
                {
                    Console.WriteLine("-1");
                    return;
                }
                
            }

            Console.WriteLine(count);




        }
    }

    class ProgramD
    {
        public void main()
        {

            //入力
            long n = long.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            int count = 0;
            long num = 0;
            long num2 = 0;
            for (int i = 0; i < n; i++)
            {
                if (s[i] == '1')
                    count++;
            }

            if (count == 0)
            {
                for (int i = 0; i < n; i++)
                    Console.WriteLine("1");
                return;
            }

            if (count == 1)
            {
                if (s[(int)n - 1] == '1')
                {
                    for (int i = 0; i < n; i++)
                    {
                        if (i == n - 1)
                            Console.WriteLine("0");
                        else
                            Console.WriteLine("2");
                    }
                }
                else
                {
                    for (int i = 0; i < n; i++)
                    {
                        if (s[i] == '1')
                            Console.WriteLine("0");
                        else if(i == n -1)
                            Console.WriteLine("2");
                        else
                            Console.WriteLine("1");
                    }
                }
                return;
            }

            for (int i = 0; i < n; i++)
            {
                if (s[i] == '1')
                {
                    num += modpow(2, n - 1 - i, count -1);
                    num2 += modpow(2, n - 1 - i, count + 1);
                }
            }

            for (int i = 0; i < n; i++)
            {
                long temp = 0;

                if (s[i] == '1')
                {
                    temp = num;
                    temp -= modpow(2, n - 1 - i, count - 1);
                    temp %= count - 1;
                }
                else
                {
                    temp = num2;
                    temp += modpow(2, n - 1 - i, count + 1);
                    temp %= count + 1;
                }

                long ans = 1;

                while(temp != 0)
                {
                    long t = 0;
                    long t2 = temp;
                    while (temp != 0)
                    {
                        t += temp % 2;
                        temp /= 2;
                    }

                    temp = t2 % t;
                    ans++;

                }

                Console.WriteLine(ans);
            }

        }

        static long modpow(long a, long n, long MOD)
        {
            if (n == 0)
                return 1;
            if (n % 2 == 0)
            {
                long temp = modpow(a, n / 2, MOD);
                return temp * temp % MOD;
            }

            return a * modpow(a, n - 1, MOD) % MOD;
        }
    }

    class ProgramE
    {

        public void main()
        {
            //入力
            int t = int.Parse(Console.ReadLine());


            for(int x = 0;x < t;x++)
            {
                int n = int.Parse(Console.ReadLine());
                for(int i = 0;i < n;i++)
                {

                }

            }


        }


    }

}