Language: C++

#include<bits/stdc++.h>

using namespace std;

string to_string(int N){
    stringstream ss;
    ss<<N;
    string ret;
    ss>>ret;
    return ret;
}

bool isCorrect(int n, string s)
{
    string solution;
    if (n % 3 == 0 && n % 5 == 0) solution = "FizzBuzz";
    else if (n % 3 == 0) solution = "Fizz";
    else if (n % 5 == 0) solution = "Buzz";
    else solution = to_string(n);
    return solution == s;
}

int main()
{
    int M, N;
    while (cin >> M >> N, N || M)
    {
        bool isExist[1000] = {};
        fill_n(isExist, M, true);
        int cnt = M, p = 0;
        for (int i = 1; i <= N; i++, p = (p + 1) % M)
        {
            while (!isExist[p]) p = (p + 1) % M;
            string s;
            cin >> s;
            if (!isCorrect(i, s))
            {
                isExist[p] = false;
                if (--cnt == 1) break;
            }
        }

        vector<int> ans;
        for (int i = 0; i < M; i++)
        {
            if (isExist[i]) ans.push_back(i);
        }
        if (ans.size() == 0) for (int i = 0; i < 1e10; i++) ;
        printf("%d", ans[0] + 1);
        for (int i = 1; i < ans.size(); i++)
        {
            printf(" %d", ans[i] + 1);
        }
        puts("");
    }
    return 0;
}

Compiler output:
a.cc: In function 'bool isCorrect(int, std::string)':
a.cc:19:30: error: call of overloaded 'to_string(int&)' is ambiguous
   19 |     else solution = to_string(n);
      |                     ~~~~~~~~~^~~
a.cc:5:8: note: candidate: 'std::string to_string(int)'
    5 | string to_string(int N){
      |        ^~~~~~~~~
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:4240:3: note: candidate: 'std::string std::__cxx11::to_string(int)'
 4240 |   to_string(int __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4259:3: note: candidate: 'std::string std::__cxx11::to_string(unsigned int)'
 4259 |   to_string(unsigned __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4275:3: note: candidate: 'std::string std::__cxx11::to_string(long int)'
 4275 |   to_string(long __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4294:3: note: candidate: 'std::string std::__cxx11::to_string(long unsigned int)'
 4294 |   to_string(unsigned long __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4310:3: note: candidate: 'std::string std::__cxx11::to_string(long long int)'
 4310 |   to_string(long long __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4327:3: note: candidate: 'std::string std::__cxx11::to_string(long long unsigned int)'
 4327 |   to_string(unsigned long long __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4401:3: note: candidate: 'std::string std::__cxx11::to_string(float)'
 4401 |   to_string(float __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4411:3: note: candidate: 'std::string std::__cxx11::to_string(double)'
 4411 |   to_string(double __val)
      |   ^~~~~~~~~
/usr/include/c++/14/bits/basic_string.h:4421:3: note: candidate: 'std::string std::__cxx11::to_string(long double)'
 4421 |   to_string(long double __val)
      |   ^~~~~~~~~