struct Node23 {
int i;
int j;
int w;
bool operator> (const Node23& n) const{
return w > n.w;
}
Node23(int i, int j) : i(i), j(j), w(pow(2,i)*pow(3,j)) {}
};
int getTopN23s(int m, int n)
{
priority_queue, greater > q;
q.push(Node23(0,0));
int sum = 0;
for(int i=0; i{
Node23 node = q.top();
q.pop();
sum = (sum + node.w) %n;
cout<if (node.i{
q.push(Node23(node.i,node.j+1));
}
else if (node.i>node.j)
{
q.push(Node23(node.i+1,node.j));
}
else
{
q.push(Node23(node.i+1,node.j));
q.push(Node23(node.i,node.j+1));
q.push(Node23(node.i+1,node.j+1));
}
}
return sum;
}