- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have a positive number n, we have to check whether n can be written as the sum of unique positive factorial numbers or not.

So, if the input is like n = 144, then the output will be True, as 4! + 5! = 24 + 120 = 144

To solve this, we will follow these steps −

fact := 1

res := a new list

x := 2

while fact <= n, do

insert fact at the end of res

fact := fact * x

x := x + 1

for i in range size of res -1 to 0, decrease by 1, do

if n >= res[i], then

n := n - res[i]

return true when n is same as 0

Let us see the following implementation to get better understanding −

class Solution: def solve(self, n): fact = 1 res = [] x = 2 while fact <= n: res.append(fact) fact = fact * x x += 1 for i in range(len(res)-1,-1,-1): if n>=res[i]: n-=res[i] return n==0 ob = Solution() print(ob.solve(144))

144

True

- Related Questions & Answers
- Check if a number can be written as sum of three consecutive integers in C++
- C++ Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers
- Check if a number can be expressed as a sum of consecutive numbers in C++
- Check if a prime number can be expressed as sum of two Prime Numbers in Python
- Check if a number can be represented as a sum of 2 triangular numbers in C++
- Check if a number can be expressed as sum two abundant numbers in C++
- C program for a number to be expressed as a sum of two prime numbers.
- Check if a number can be expressed as a^b in Python
- Program to check a number is ugly number or not in Python
- Program to check a string can be split into three palindromes or not in Python
- Find if n can be written as product of k numbers in C++
- Program to check a string can be broken into given list of words or not in python
- Python program to check if a number is Prime or not
- Python program to check a number n is weird or not
- Count Triplets such that one of the numbers can be written as sum of the other two in C++

Advertisements