ITGUY26 - Editorial

Problem: Contest Page | CodeChef

DIFFICULTY:

EASY.

PROBLEM:

The chef was busy in solving algebra, he found some interesting results, that there are many numbers which can be formed by the sum of the factorial of the digits, he wrote all those interesting numbers in the diary(in increasing order) and went to sleep. Cheffina came and stole his diary, in morning chef found that his diary is missing. Now the chef wants your help to find those numbers, Chef asks you whether N is that interesting number or not. If N is an interesting number then print 1. Else print 0.

Program:

#include<bits/stdc++.h>
using namespace std;
int main()
 {
	//code
	ios_base::sync_with_stdio(false);
   	cin.tie(NULL);
   	cout.tie(NULL);
   	int t;
   	cin>>t;
   	while(t--){
   		int i;
   		cin>>i;
   	    if(i==1 || i==2 || i== 145 || i== 40585 )cout<<1<<"\n";
	    else cout<<0<<"\n";
	
   	}
	return 0;
}

import math
arr=[]
for i in range(9):
arr.append(math.factorial(i))
for i in range(int(input())):
N=input()
sum=0
for i in range(len(N)):
sum+=arr[int(N[i])]
if(sum==int(N)):
print(1)
else:
print(0)
what’s wrong in my code it’s getting runtime error.

@references Please can you tell why am I getting wrong answer for my code although all test cases are running fine.
https://www.codechef.com/viewsolution/40636774

Edge case. For N=0, ans=0. You missed this

1 Like

Oh, yes ,got it. Thanks!