1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Karol Kosinski 2026
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),_b=(b);i<_b;++i)
#define FR_(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FD_(i,b,a) for(int i=(b),_a=(a);i>=_a;--i)
#define ALL(c) (c).begin(),(c).end()
#define SIZE(c) int((c).size())
#define X first
#define Y second
#define endl '\n'
#define NAM(x) #x,'=',x
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
template<class...T> void _cout(T...a){(cout<<...<<a);}

#ifndef ENABLE_DEBUG
#define DEB(k,p,f,x...)
#else
#define DEB(k,p,f,x...) {if(k)_cout("------",setw(4),__LINE__," : ",__FUNCTION__,endl);if(p)f(x);}
#endif
#define DEBF(f,x...)    DEB(1,1,f,x)
#define DEBL            DEBF(void,0)
#define DEBC(p,x...)    DEB(0,p,_cout,x)
#define DEBUG(x...)     DEBC(1,x)

constexpr int NX = 10'000'005;

#define C_DEF(p) int C##p[p]
#define C_REF(p) C##p[ a % p ]
#define C_MAX(p) FOR(i,0,p) res = max( res, C##p[i] )

set<int> A;
bool P[NX];
int Tmp[NX];
 C_DEF(2);  C_DEF(3);  C_DEF(5);  C_DEF(7);
C_DEF(11); C_DEF(13); C_DEF(17); C_DEF(19);
C_DEF(23); C_DEF(29); C_DEF(31); C_DEF(37);
C_DEF(41); C_DEF(43); C_DEF(47); C_DEF(53);
C_DEF(59); C_DEF(61); C_DEF(67); C_DEF(71);
vector<int> Prime;

void eratos(int n)
{
    P[0] = P[1] = true;
    int m = n/2;
    FR_(i,2,m)
    {
        if ( P[i] ) continue;
        if ( i > 71 )
            Prime.push_back(i);
        int j = i + i;
        while ( j <= m )
        {
            P[j] = true;
            j += i;
        }
    }
}

int solve(int n)
{
    int a, res = 2;
    cin >> a;
    auto [iter, inserted] = A.insert(a);
    if ( not inserted )
    {
        A.erase(iter);
        --  C_REF(2); --  C_REF(3); --  C_REF(5); --  C_REF(7);
        -- C_REF(11); -- C_REF(13); -- C_REF(17); -- C_REF(19);
        -- C_REF(23); -- C_REF(29); -- C_REF(31); -- C_REF(37);
        -- C_REF(41); -- C_REF(43); -- C_REF(47); -- C_REF(53);
        -- C_REF(59); -- C_REF(61); -- C_REF(67); -- C_REF(71);
    }
    else
    {
        ++  C_REF(2); ++  C_REF(3); ++  C_REF(5); ++  C_REF(7);
        ++ C_REF(11); ++ C_REF(13); ++ C_REF(17); ++ C_REF(19);
        ++ C_REF(23); ++ C_REF(29); ++ C_REF(31); ++ C_REF(37);
        ++ C_REF(41); ++ C_REF(43); ++ C_REF(47); ++ C_REF(53);
        ++ C_REF(59); ++ C_REF(61); ++ C_REF(67); ++ C_REF(71);
    }
    DEBUG( "* ", NAM(a), "  ", NAM(inserted), "  ", NAM(SIZE(A)), endl )
    
    if ( SIZE(A) <= 2 )
    {
        return SIZE(A);
    }
     C_MAX(2);  C_MAX(3);  C_MAX(5);  C_MAX(7);
    C_MAX(11); C_MAX(13); C_MAX(17); C_MAX(19);
    C_MAX(23); C_MAX(29); C_MAX(31); C_MAX(37);
    C_MAX(41); C_MAX(43); C_MAX(47); C_MAX(53);
    C_MAX(59); C_MAX(61); C_MAX(67); C_MAX(71);
    for ( auto k : Prime )
    {
        DEBUG( "Trying: ", NAM(k), endl );
        if ( n/k < res or res == SIZE(A) )
        {
            break;
        }
        FOR(i,0,k) Tmp[i] = 0;
        for ( auto v : A )
        {
            ++ Tmp[ v % k ];
        }
        res = max( res, *max_element( Tmp, Tmp + k ) );
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    eratos(n);
    FOR(i,0,q)
    {
        cout << solve(n) << endl;
    }
    return 0;
}