Language: C++

#include <gmpxx.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
// int => mpz_class
// scanf("%d", &x); => std::cin >> x;
// printf("%d\n", x); => std::cout << x << "\n";

// コンパイル時に -lgmpxx -lgmp

int CountE(int k) {
    int count = 0;
    for (int i = k; i >= 1; i /= 10) {
        count++;
    }
    return count;
}

int StartK(int x) {
    int k = 7;
    for (int i = 1; i < x; i++) {
        k = k * 10 + 7;
    }
    return k;
}

int main() {
    long int k;
    scanf("%ld", &k);
    int flag = 0;
    mpz_class mk777 = StartK(CountE(k)); /* 7がkの桁数並んだ数 */
    // std::cout << mk777 << "\n";

    for (int i = 0; i < k * 1000; i++) {
        if (mk777 % k == 0) {
            printf("%d\n", i + CountE(k));
            flag = 1;
            return 0;
        }
        mk777 = mk777 * 10 + 7;
    }

    if (flag == 0) {
        printf("-1\n");
    }
    return 0;
}

Compiler output:
/usr/bin/ld: /tmp/cc5RR38Y.o: in function `__gmp_binary_plus::eval(__mpz_struct*, __mpz_struct const*, unsigned long)':
a.cc:(.text._ZN17__gmp_binary_plus4evalEP12__mpz_structPKS0_m[_ZN17__gmp_binary_plus4evalEP12__mpz_structPKS0_m]+0x27): undefined reference to `__gmpz_add_ui'
/usr/bin/ld: /tmp/cc5RR38Y.o: in function `__gmp_binary_plus::eval(__mpz_struct*, __mpz_struct const*, long)':
a.cc:(.text._ZN17__gmp_binary_plus4evalEP12__mpz_structPKS0_l[_ZN17__gmp_binary_plus4evalEP12__mpz_structPKS0_l]+0x4d): undefined reference to `__gmpz_sub_ui'
/usr/bin/ld: /tmp/cc5RR38Y.o: in function `__gmp_binary_multiplies::eval(__mpz_struct*, __mpz_struct const*, long)':
a.cc:(.text._ZN23__gmp_binary_multiplies4evalEP12__mpz_structPKS0_l[_ZN23__gmp_binary_multiplies4evalEP12__mpz_structPKS0_l]+0x27): undefined reference to `__gmpz_mul_si'
/usr/bin/ld: /tmp/cc5RR38Y.o: in function `__gmp_binary_modulus::eval(__mpz_struct*, __mpz_struct const*, long)':
a.cc:(.text._ZN20__gmp_binary_modulus4evalEP12__mpz_structPKS0_l[_ZN20__gmp_binary_modulus4evalEP12__mpz_structPKS0_l]+0x32): undefined reference to `__gmpz_tdiv_r_ui'
/usr/bin/ld: /tmp/cc5RR38Y.o: in function `__gmp_binary_equal::eval(__mpz_struct const*, long)':
a.cc:(.text._ZN18__gmp_binary_equal4evalEPK12__mpz_structl[_ZN18__gmp_binary_equal4evalEPK12__mpz_structl]+0x1f): undefined reference to `__gmpz_cmp_si'
/usr/bin/ld: /tmp/cc5RR38Y.o: in function `__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::init_si(long)':
a.cc:(.text._ZN10__gmp_exprIA1_12__mpz_structS1_E7init_siEl[_ZN10__gmp_exprIA1_12__mpz_structS1_E7init_siEl]+0x1f): undefined reference to `__gmpz_init_set_si'
/usr/bin/ld: /tmp/cc5RR38Y.o: in function `__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::~__gmp_expr()':
a.cc:(.text._ZN10__gmp_exprIA1_12__mpz_structS1_ED2Ev[_ZN10__gmp_exprIA1_12__mpz_structS1_ED5Ev]+0x14): undefined reference to `__gmpz_clear'
/usr/bin/ld: /tmp/cc5RR38Y.o: in function `__gmp_expr<__mpz_struct [1], __mpz_struct [1]>::__gmp_expr<__gmp_binary_expr<__gmp_expr<__mpz_struct [1], __mpz_struct [1]>, long, __gmp_binary_modulus> >(__gmp_expr<__mpz_struct [1], __gmp_binary_expr<__gmp_expr<__mpz_struct [1], __mpz_struct [1]>, long, __gmp_binary_modulus> > const&)':
a.cc:(.text._ZN10__gmp_exprIA1_12__mpz_structS1_EC2I17__gmp_binary_exprIS2_l20__gmp_binary_modulusEEERKS_IS1_T_E[_ZN10__gmp_exprIA1_12__mpz_structS1_EC5I17__gmp_binary_exprIS2_l20__gmp_binary_modulusEEERKS_IS1_T_E]+0x18): undefined reference to `__gmpz_init'
collect2: error: ld returned 1 exit status