Ugly numbersssssss

why is it giving wrong answer?

#include<bits/stdc++.h>

using namespace std;

int dp[1000000]={0};

void func(){
//int dp[10000000]={0};
dp[1]=1;dp[2]=1;dp[3]=1;dp[5]=1;

for(long long i=1;i<1000000;i++){
    if(dp[i]==1){
        if(i*2<1000000)dp[i*2]=1;
        if(i*3<1000000)dp[i*3]=1;
        if(i*5<1000000)dp[i*5]=1;
    }
}

}

int main(){

long long t,n;
func();
cin>>t;
while(t--){
    cin>>n;
    long long c=0;
    for(long long i=1;i<1000000;i++){
        if(dp[i]==1)
        c++;
        if(c==n){
            cout<<i<<endl;
            break;
        }
    }
}

return 0;

}

Plz send your code by saving on ide only

have it

You are using slightly wrong approach in your code, in this code, you are required to maintain
long long int i2=0,i3=0,i5=0;
long long int next_multiple_2=2;
long long int next_multiple_3=3;
long long int next_multiple_5=5;
After that you need to use a loop from 1 to n, and then you need to check if(next_ugly_no==next_multiple_2)
{
i2++;
next_multiple_2=dp[i2]*2;
}
This condition needs to be checked for 3 as well as 5, and finally you can print your answer. Try using this approach

@yuktimutreja01 sorry…i didnt understand


Plz refer to this youtube link and then try to code based on this approach only.