Thanks @agave and @StefanPochmann , I have rewritten it into cpp version : )

int nthUglyNumber(int n) {
priority_queue< pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
pq.push(make_pair(1,1));
int val, fact;
for(int i = 0; i < n ; i++){
auto t = pq.top();
val = t.first;
fact = t.second;
pq.pop();
// handle overflow problem
if( fact <= 2 && val < 1073741823.5 ) pq.push(make_pair(val*2, 2));
if( fact <= 3 && val < 715827882.3 ) pq.push(make_pair(val*3, 3));
if( fact <= 5 && val < 429496729.4 ) pq.push(make_pair(val*5, 5));
}
return val;
}