Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
N’th Smart Number in C++
A smart number is a number that contains at least three distinct prime factors. You are given a number N. Find the n-th smart number.
The smart number series are
30, 42, 60, 66, 70, 78...
Algorithm
- Initialise the number N.
- Initialise the count to 0.
- Write a function that checks whether the given number is prime or not.
- Write a function that checks whether the number is smart or not.
- Write a loop that iterates from 30 as first smart number is 30.
- Check whether the current number is smart number or not using the prime number function.
- Increment the count by 1 when you find a smart number.
- Return the smart number when you count is equals to N.
Implementation
Following is the implementation of the above algorithm in C++
#includeusing namespace std; bool isPrime(int n) { if (n Output
If you run the above code, then you will get the following result.
174
Advertisements
