Check whether a number is Sublime number or not Last Updated : 25 Aug, 2023 Comments Improve Suggest changes Like Article Like Report Given a number N, the task is to check whether the number is a Sublime number or not. Sublime numbers are defined as positive numbers whose sum of positive divisors and count of positive divisors are both perfect numbers. Examples: Input: N = 12Output: TrueExplanation: 12 is a sublime number because its divisors are 1, 2, 3, 4, 6, and 12. So there are 6 factors of it and 6 is a perfect number and 1+2+3+4+6+12=28, which is also a perfect number. So 12 is a Sublime number. Input: N = 24Output: FalseExplanation: 24 is a not sublime number because the divisors of 24 are 1, 2, 3, 4, 6, 8, 12 and 24. So there are 8 factors and which is not a perfect number and 1+2+3+4+6+8+12+24=60, Which is not a perfect number. So 24 is not a Sublime number. Approach: We have to implement two main logic: Find and Count Divisors of a Number LogicPerfect Number Checking.Below are the steps involved in the implementation of the code: Initialize a number n.Find the divisors of the given number (n).Count the total number of divisors of the given number (n) and store it in a variable (count).Sum up the divisors, and store the result in a variable (sum).At last, check whether count and sum are perfect numbers or not.If both are perfect numbers, the given number (n) is a sublime number.Else, not a sublime number.Below is the implementation of the code: C++ // C++ Implementation to Check whether // a number is Sublime Number or Not. #include <iostream> using namespace std; // Check whether the number is // sublime or not void checkSublime(int num) { int s = 0, f = 0, s1 = 0, s2 = 0, i, j; for (i = 1; i <= num; i++) { if (num % i == 0) { // Finds the divisors // and sum up them s = s + i; // Counts the number // of divisors f++; } } // Check for perfect number for (j = 1; j < s; j++) { if (s % j == 0) s1 = s1 + j; } for (j = 1; j < f; j++) { if (f % j == 0) s2 = s2 + j; } if (s1 == s && s2 == f) cout << "True" << endl; else cout << "False" << endl; } // Driver code int main() { int n = 12; // Function call checkSublime(n); return 0; } Java // java program to Check whether the number is sublime or // not public class SublimeNumber { // Check whether the number is sublime or not public static void checkSublime(int num) { int s = 0, f = 0, s1 = 0, s2 = 0, i, j; for (i = 1; i <= num; i++) { if (num % i == 0) { // Finds the divisors and sums them up s = s + i; // Counts the number of divisors f++; } } // Check for perfect number for (j = 1; j < s; j++) { if (s % j == 0) s1 = s1 + j; } for (j = 1; j < f; j++) { if (f % j == 0) s2 = s2 + j; } if (s1 == s && s2 == f) System.out.println("True"); else System.out.println("False"); } // Driver code public static void main(String[] args) { int n = 12; // Function call checkSublime(n); } } // This code is contributed by shivamgupta0987654321 Python3 # python3 Implementation to Check whether # a number is Sublime Number or Not. def checkSublime(num): s = 0 f = 0 s1 = 0 s2 = 0 for i in range(1, num+1): if num % i == 0: # Finds the divisors and sums them up s += i # Counts the number of divisors f += 1 # Check for perfect number for j in range(1, s): if s % j == 0: s1 += j for j in range(1, f): if f % j == 0: s2 += j if s1 == s and s2 == f: print("True") else: print("False") # Driver code if __name__ == "__main__": n = 12 # Function call checkSublime(n) # This code is contributed by shivamgupta310570 C# // C# Implementation to Check whether // a number is Sublime Number or Not. using System; public class SublimeNumber { // Check whether the number is sublime or not public static void CheckSublime(int num) { int s = 0, f = 0, s1 = 0, s2 = 0, i, j; for (i = 1; i <= num; i++) { if (num % i == 0) { // Finds the divisors and sums them up s = s + i; // Counts the number of divisors f++; } } // Check for perfect number for (j = 1; j < s; j++) { if (s % j == 0) s1 = s1 + j; } for (j = 1; j < f; j++) { if (f % j == 0) s2 = s2 + j; } if (s1 == s && s2 == f) Console.WriteLine("True"); else Console.WriteLine("False"); } // Driver code public static void Main(string[] args) { int n = 12; // Function call CheckSublime(n); } } JavaScript // Check whether the number is // sublime or not function checkSublime(num) { let s = 0, f = 0, s1 = 0, s2 = 0; for (let i = 1; i <= num; i++) { if (num % i === 0) { // Finds the divisors // and sum up them s += i; // Counts the number // of divisors f++; } } // Check for perfect number for (let j = 1; j < s; j++) { if (s % j === 0) s1 += j; } for (let j = 1; j < f; j++) { if (f % j === 0) s2 += j; } if (s1 === s && s2 === f) console.log("True"); else console.log("False"); } // Driver code const n = 12; // Function call checkSublime(n); OutputTrueTime Complexity: O(N)Auxiliary Space: O(1) as using constant variables Comment More infoAdvertise with us Next Article Check whether a number is Sublime number or not karan_kumar19 Follow Improve Article Tags : Mathematical DSA Basic Coding Problems Practice Tags : Mathematical Similar Reads Check Whether a number is Duck Number or not A Duck number is a positive number which has zeroes present in it, For example 3210, 8050896, 70709 are all Duck numbers. Please note that a numbers with only leading 0s is not considered as Duck Number. For example, numbers like 035 or 0012 are not considered as Duck Numbers. A number like 01203 is 8 min read Check whether a given number N is a Nude Number or not Given an integer N, the task is to check whether N is a Nude number or not. A Nude number is a number that is divisible by all of its digits (which should be nonzero). Example: Input: N = 672 Output: Yes Explanation: Since, 672 is divisible by all of its three digits 6, 7 and 2. Therefore the output 4 min read Check if a number is a Krishnamurthy Number or not A Krishnamurthy number is a number whose sum of the factorial of digits is equal to the number itself.For example, 145 is the sum of the factorial of each digit.1! + 4! + 5! = 1 + 24 + 120 = 145 Examples: Input : 145Output : YESExplanation: 1! + 4! + 5! = 1 + 24 + 120 = 145, which is equal to input, 10 min read PHP | Check if a number is armstrong number Given a number, we need to check whether it is an armstrong number or not in PHP. An Armstrong number is the one whose value is equal to the sum of the cubes of its digits.Examples: Input : 407 Output : Yes 407 = (4*4*4) + (0*0*0) + (7*7*7) = 64 + 0 + 343 = 407 Input : 303 Output : No Approach: For 2 min read Program to check if input is an integer or a string Write a function to check whether a given input is an integer or a string. Definition of an integer : Every element should be a valid digit, i.e '0-9'. Definition of a string : Any one element should be an invalid digit, i.e any symbol other than '0-9'. Examples: Input : 127Output : IntegerExplanati 15+ min read Check if a number is magic (Recursive sum of digits is 1) A number is said to be a magic number, if the sum of its digits are calculated till a single digit recursively by adding the sum of the digits after every addition. If the single digit comes out to be 1,then the number is a magic number. For example- Number= 50113 => 5+0+1+1+3=10 => 1+0=1 This 7 min read Check if a given string is a valid number (Integer or Floating Point) | SET 1(Basic approach) Validate if a given string is numeric. Examples: Input : str = "11.5" Output : true Input : str = "abc" Output : false Input : str = "2e10" Output : true Input : 10e5.4 Output : false The following cases need to be handled in the code. Ignore the leading and trailing white spaces.Ignore the '+', '-' 11 min read Almost Perfect Number Given a number n, check it is the Almost Perfect number or not. Almost perfect number is a natural number whose sum of all divisors including 1 and the number itself is equal to 2n - 1.Example : Input: n = 16Output: YesExplanation: sum of divisors = 1 + 2 + 4 + 8 + 16 = 31 = 2n - 1 Input: n = 9Outpu 4 min read Check if a given string is a valid number (Integer or Floating Point) in Java | SET 2 (Regular Expression approach) In Set 1, we have discussed general approach to check whether a string is a valid number or not. In this post, we will discuss regular expression approach to check for a number. Examples: Input : str = "11.5" Output : true Input : str = "abc" Output : false Input : str = "2e10" Output : true Input : 3 min read JavaScript Number isInteger() Method The Number.isInteger() method in JavaScript is useful for checking whether a number is a whole number or not. Syntax:Number.isInteger(value);Parameters:value: The value to be checked.Return Value:It returns a boolean value,i.e. either true or false. It will return true if the passed value is of the 1 min read Like