Help me in solving LUCKYSTR problem

My issue

Didn’t passed all test case , i looped through every substring to check if present in set

My code

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

bool isLucky(string s,set<string>st,int index)
{
    int n=s.size();
    for(int i=0;i<n;i++)
    {
        string temp="";
        for(int j=i;j<n;j++)
        {
            temp+=s[j];
            if(st.find(temp)!=st.end())
            {
                return true;
            }
            
        }
    }
    
    return false;
}
int main() {
	// your code goes here
	string n,k;
	cin>>k;
	cin>>n;
	set<string>st;
	int i=stoi(k);
	string temp;
	while(i>0)
	{
	    cin>>temp;
	    st.insert(temp);
	    i--;
	    
	}
	
	i=stoi(n);
	int num;
	while(i>0)
	{
	    cin>>num;
	    string no=to_string(num);
        if(isLucky(no,st,0)) cout<<"Good"<<endl;
        else cout<<"Bad"<<endl;
        i--;
	    
	}

	return 0;
}

Problem Link: LUCKYSTR Problem - CodeChef