• + 0 comments
    bool isprime(int n)
    {
        for(int i=2;i<(n/2)+1;i++)
        {
            if(n%i == 0)
            {
                return false;
            }
        }
        return true;
    }
    vector<int> waiter(vector<int> number, int q) 
    {
        vector<int> p,a,b,res;
        vector<int> temp;
        int x;
        for(int i=2;i<10000;i++)
        {
            if(isprime(i))
            {
                p.push_back(i);
            }
        }    
        
        for(int i=0;i<q;i++)
        {
            int size = number.size();
            for(int j=0;j<size;j++)
            {
                x = number.back();
                
                if(x%p[i] == 0)
                {
                    b.push_back(x);
                    number.pop_back();
                }
                else
                {
                    a.push_back(x);
                    number.pop_back();
                }
            }
            number = a;
            a.clear();
            while(!b.empty())
            {
                res.push_back(b.back());
                b.pop_back();
            } 
        }
        while(!number.empty())
        {
            res.push_back(number.back());
            number.pop_back();
        }
        return res;
    }