Why Choose Us?
0% AI Guarantee
Human-written only.
24/7 Support
Anytime, anywhere.
Plagiarism Free
100% Original.
Expert Tutors
Masters & PhDs.
100% Confidential
Your privacy matters.
On-Time Delivery
Never miss a deadline.
Andrew loves numbers whose prime factor includes 2,3 or 5
Andrew loves numbers whose prime factor includes 2,3 or 5. He wants to know the Nth such number. Help Andrew find that.
Input:- N - nth number
Output:- Nth number matching Andrew’s specification.
note
Constraints
1<=N<=1650
view_list
Examples
Input:
10
Output:
12
Explanation:
1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 numbers matching Andrew’s specification.
label_important
Important Notes
1 is a part of the series
Expert Solution
class solution
{
public:
int andrew_numbers(int n)
{
priority_queue,greater> pq;
pq.push(1);
int p,a;
p=-1;
for(int i=1;i<=s;i++)
{
while(pq.top()==p)
{
pq.pop();
}
a=pq.top();
pq.push(a*2);
pq.push(a*3);
pq.push(a*5);
p=a;
}
return a;
}
};
Archived Solution
You have full access to this solution. To save a copy with all formatting and attachments, use the button below.
For ready-to-submit work, please order a fresh solution below.





