Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Check Whether a Number Is Strong

Basic Acceptance 66.91% Points 10.00

You are given a positive integer n. Your task is to determine whether it is a Strong number. A number is Strong if it equals the sum of the factorials of its digits.

Examples
Example 1

Input: n = 145
Output: Yes
Explanation: The sum of the factorials of the digits is 1! + 4! + 5! = 1 + 24 + 120 = 145. Therefore, 145 is a Strong number.

Example 2

Input: n = 123
Output: No
Explanation: The sum of the factorials of the digits is 1! + 2! + 3! = 1 + 2 + 6 = 9, which is not equal to 123.

Example 3

Input: n = 2
Output: Yes
Explanation: The only digit is 2, and 2! = 2. Therefore, 2 is a Strong number.

Constraints
  • 1 <= n <= 109
Companies
Apple Infosys Mastercard
Topics
Data Structures Basics Basics
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions