#include <bits/stdc++.h>
using namespace std;
#define Seny ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()
#define print(v) for(auto q : v)cout<<q<<" "
#define ll long long
const int mod = 1e9 + 7;
//const int N = 1e6;
map<int,int>all;
void pre(int N)
{
for (int i = 2; i <= N; ++i) {
int tmp = i;
for (int j = 2; j*j <= i; ++j) {
while (tmp % j == 0)
{
all[j]++;
tmp/=j;
}
}
if(tmp > 1)
all[tmp]++;
}
return;
}
void solve() {
int n,q;cin >> n >> q;
pre(n);
while (q--)
{
int op,x;cin >> op >> x;
if(op == 1)
{
int tmp = x;
for (int i = 2; i*i <= x; ++i) {
while (tmp % i == 0)
{
all[i]++;
tmp/=i;
}
}
if(tmp > 1)
all[tmp]++;
}
else
{
map<int,int>check;
int tmp = x;
for (int i = 2; i*i <= x; ++i) {
while (tmp % i == 0)
{
check[i]++;
tmp/=i;
}
}
if(tmp > 1)
check[tmp]++;
int ans = 1e9;
for(auto i : check)
{
ans = min(ans,(int)floor((double)all[i.first]/i.second));
}
cout << ans <<'\n';
}
}
// for(auto i :all)
// {
// cout << i.first<<" "<<i.second;
// }
}
signed main() {
Seny
int t = 1;
//cin >> t;
while (t--)
solve();
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgU2VueSBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApO2Npbi50aWUoMCk7Y291dC50aWUoMCk7CiNkZWZpbmUgYWxsKHYpIHYuYmVnaW4oKSx2LmVuZCgpCiNkZWZpbmUgcHJpbnQodikgZm9yKGF1dG8gcSA6IHYpY291dDw8cTw8IiAiCiNkZWZpbmUgbGwgbG9uZyBsb25nCmNvbnN0IGludCBtb2QgPSAxZTkgKyA3OwovL2NvbnN0IGludCBOID0gMWU2OwoKbWFwPGludCxpbnQ+YWxsOwoKdm9pZCBwcmUoaW50IE4pCnsKICAgIGZvciAoaW50IGkgPSAyOyBpIDw9IE47ICsraSkgewogICAgICAgIGludCB0bXAgPSBpOwogICAgICAgIGZvciAoaW50IGogPSAyOyBqKmogPD0gaTsgKytqKSB7CiAgICAgICAgICAgIHdoaWxlICh0bXAgJSBqID09IDApCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGFsbFtqXSsrOwogICAgICAgICAgICAgICAgdG1wLz1qOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmKHRtcCA+IDEpCiAgICAgICAgICAgIGFsbFt0bXBdKys7CiAgICB9CiAgICByZXR1cm47Cn0KCnZvaWQgc29sdmUoKSB7CiAgICBpbnQgbixxO2NpbiA+PiBuID4+IHE7CiAgICBwcmUobik7CiAgICB3aGlsZSAocS0tKQogICAgewogICAgICAgIGludCBvcCx4O2NpbiA+PiBvcCA+PiB4OwogICAgICAgIGlmKG9wID09IDEpCiAgICAgICAgewogICAgICAgICAgICBpbnQgdG1wID0geDsKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDI7IGkqaSA8PSB4OyArK2kpIHsKICAgICAgICAgICAgICAgIHdoaWxlICh0bXAgJSBpID09IDApCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgYWxsW2ldKys7CiAgICAgICAgICAgICAgICAgICAgdG1wLz1pOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKHRtcCA+IDEpCiAgICAgICAgICAgICAgICBhbGxbdG1wXSsrOwogICAgICAgIH0KICAgICAgICBlbHNlCiAgICAgICAgewogICAgICAgICAgICBtYXA8aW50LGludD5jaGVjazsKICAgICAgICAgICAgaW50IHRtcCA9IHg7CiAgICAgICAgICAgIGZvciAoaW50IGkgPSAyOyBpKmkgPD0geDsgKytpKSB7CiAgICAgICAgICAgICAgICB3aGlsZSAodG1wICUgaSA9PSAwKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGNoZWNrW2ldKys7CiAgICAgICAgICAgICAgICAgICAgdG1wLz1pOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmKHRtcCA+IDEpCiAgICAgICAgICAgICAgICBjaGVja1t0bXBdKys7CiAgICAgICAgICAgIGludCBhbnMgPSAxZTk7CiAgICAgICAgICAgIGZvcihhdXRvIGkgOiBjaGVjaykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgYW5zID0gbWluKGFucywoaW50KWZsb29yKChkb3VibGUpYWxsW2kuZmlyc3RdL2kuc2Vjb25kKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY291dCA8PCBhbnMgPDwnXG4nOwogICAgICAgIH0KICAgIH0KLy8gICAgZm9yKGF1dG8gaSA6YWxsKQovLyAgICB7Ci8vICAgICAgICBjb3V0IDw8IGkuZmlyc3Q8PCIgIjw8aS5zZWNvbmQ7Ci8vICAgIH0KfQoKc2lnbmVkIG1haW4oKSB7CiAgICBTZW55CiAgICBpbnQgdCA9IDE7CiAgICAvL2NpbiA+PiB0OwogICAgd2hpbGUgKHQtLSkKICAgICAgICBzb2x2ZSgpOwp9