Ugly numbers------------------

where my code is wrong

#include <bits/stdc++.h> using namespace std; int main() { int t,n; int fact[1000000]={0}; int arr[10005]; fact[1]=1; for(int i=2;i<=1000000;i+=2){ fact[i]=1; } for(int i=3;i<=1000000;i+=3){ fact[i]=1; } for(int i=5;i<=1000000;i+=5){ fact[i]=1; } int z=1; for(int i=1;i<=1000000;i++){ if(fact[i]){ arr[z]=i;z++; } } /* for(int i=1;i<=15;i++){ cout<<arr[i]<<" "; }*/ cin>>t; while(t–){ cin>>n; cout<<arr[n]<<endl; } return 0; }

Refer these:


plz once look my code i think my solution is fine and corect

Please save your code on ide.codingblocks.com and then share its link.

@riprogerdep Your code is giving incorrect output.
Some expected outputs are:
Input : n = 7
Output : 8

Input : n = 10
Output : 12

Input : n = 15
Output : 24

Input : n = 150
Output : 5832

Check this:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.