Language: C++

#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
string s, t;
//hashing
int x, mod;
string bigS;
string bigT;

bool checkPrime(int x) {
    for (int i=2; i*i<=x; i++) if (x%i==0) return 0;
    return 1;
}

int rand_ll() {
    int u = rand();
    u = (int)rand() + (u<<15);
    u = (int)rand() + (u<<15);
    u = (int)rand() + (u<<15);;
    return u;
}

void randomizedMod() {
    x = 10;
    while (!checkPrime(x)) {
        x = 29 + rand() % 73;
    }
    mod = 10;
    while (!checkPrime(mod)) {
        mod = 998000000+ rand_ll()%1000000000;
    }
}

int hashT = 0;
void recalculateHashT() {
    int ans = 0;
    for (char c:bigT) {
        ans = (ans*x + (c-'a'+2))%mod;
    }
    hashT = ans;
}

vector <int> prefSumS = {0};

int powMod(int u, int v) {
    if (v == 0) return 1;
    int mid = powMod(u, v/2);
    mid = (mid*mid)%mod;
    if (v%2==0) return mid;
    else return (mid*u)%mod;
}

bool checkSubstr() {
    int sz = bigT.size();
    int p = powMod(x, sz);
    for (int i=sz; i<prefSumS.size(); i++) {
        if ((prefSumS[i] - (prefSumS[i - sz] * p)%mod + mod)%mod == hashT) return 1;
    }
    return 0;
}

// main solution goes here:
void execute(int test_number)
{
    srand(time(0));
    randomizedMod();

    cin>>s>>t;
    s = s+s+s;
    bigS = s;
    while (bigS.size() <= t.size()) {
        bigS += s;
    }

    for (char c:bigS) {
        prefSumS.push_back((prefSumS.back() * x + (c-'a'+2))%mod);
    }

    int l = 0, r = 5000005;
    while (r > l) {
        int mid = (l+r)/2 + 1;
        if (mid*(int)t.size() > bigS.size()) {
            r = mid - 1;
            continue;
        }

        bigT = "";
        for (int i=0; i<mid; i++) for (char c: t) bigT.push_back(t);
        recalculateHashT();

        if (checkSubstr()) l = mid;
        else r = mid-1;
    }

    int ans = l;
    for (char c:bigS) {
        prefSumS.push_back((prefSumS.back() * x + (c-'a'+2))%mod);
    }
    bigS = bigS + bigS;
    l = 0, r = 5000005;
    while (r > l) {
        int mid = (l+r)/2 + 1;
        if (mid*(int)t.size() > bigS.size()) {
            r = mid - 1;
            continue;
        }

        bigT = "";
        for (int i=0; i<mid; i++) {
            for (char c: t) bigT.push_back(t);
        }
        recalculateHashT();

        if (checkSubstr()) l = mid;
        else r = mid-1;
    }
    if (ans < l) {
        cout<<-1;
        return;
    }
    cout<<ans<<"\n";
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

Compiler output:
a.cc:190:42: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
  190 |     if (input_from_file) freopen(filename"."in_extension, "r", stdin);
      |                                          ^
a.cc:191:41: warning: invalid suffix on literal; C++11 requires a space between literal and string macro [-Wliteral-suffix]
  191 |     if (output_to_file) freopen(filename"."out_extension, "w", stdout);
      |                                         ^
a.cc: In function 'void execute(long long int)':
a.cc:124:66: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'char'
  124 |         for (int i=0; i<mid; i++) for (char c: t) bigT.push_back(t);
      |                                                                  ^
      |                                                                  |
      |                                                                  std::string {aka std::__cxx11::basic_string<char>}
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:1572:24: note:   initializing argument 1 of 'void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::push_back(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1572 |       push_back(_CharT __c)
      |                 ~~~~~~~^~~
a.cc:146:44: error: cannot convert 'std::string' {aka 'std::__cxx11::basic_string<char>'} to 'char'
  146 |             for (char c: t) bigT.push_back(t);
      |                                            ^
      |                                            |
      |                                            std::string {aka std::__cxx11::basic_string<char>}
/usr/include/c++/14/bits/basic_string.h:1572:24: note:   initializing argument 1 of 'void std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::push_back(_CharT) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
 1572 |       push_back(_CharT __c)
      |                 ~~~~~~~^~~