Given a Number . The task is to check if N is a Trojan Number or not.
Trojan Number is a number that is a strong number but not a perfect power. A number N is known as a strong number if, for every prime divisor or factor p of N, p2 is also a divisor. In other words, every prime factor appears at least twice.
All Trojan numbers are strong. However, not all strong numbers are Trojan numbers: only those that cannot be represented as mk, where m and k are positive integers greater than 1.
Input : N = 108 Output : YES Input : N = 8 Output : NO
The idea is to store the count of each prime factor and check if the count is greater than 2 then it will be a Strong Number.
This part can easily be calculated by prime factorization through sieve.
The next step is to check if the given number cannot be expressed as xy. To check whether a number is perfect power or not refer to this article.
Below is the implementation of above problem:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if the binary representation of a number has equal number of 0s and 1s in blocks
- Check whether all the rotations of a given number is greater than or equal to the given number or not
- Check if a number is divisible by all prime divisors of another number
- Check if a large number is divisible by a number which is a power of 2
- Check if a number with even number of digits is palindrome or not
- Program to check whether a number is Proth number or not
- Check if the number is a Prime power number
- Check if a number is an Unusual Number or not
- Check whether a given number is an ugly number or not
- Check whether a number is Non-hypotenuse number
- Check if a number is a Krishnamurthy Number or not
- Check if a number is an Achilles number or not
- Check whether a given number N is a Nude Number or not
- Check whether given number N is a Moran Number or not
- How to check if a given number is Fibonacci number?
- Check Whether a number is Duck Number or not
- Check if a number ends with another number or not
- Check if a number starts with another number or not
- Check whether the given number is Euclid Number or not
- Check if a number is a Mystery Number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.