Hot Topics

Optum Solution
Technical Round
#include <iostream>
#include <unordered_map>
using namespace std;
unordered_map<int, int> factorials;
// Function to calculate the factorial of a number
int factorial(int n) {
if (n == 0 || n == 1) {
return 1;
}
return n * factorial(n - 1);
}
// Function to calculate the sum of the factorials of the digits of a number
int sum_of_factorial_of_digits(int n) {
int sum = 0;
while (n > 0) {
int digit = n % 10;
if (factorials.count(digit) == 0) {
factorials[digit] = factorial(digit);
}
sum += factorials[digit];
n /= 10;
}
return sum;
}
int main() {
int n;
cout << "Enter a number: ";
cin >> n;
// Check if the sum of the factorials of the digits of the number is equal to the number
if (sum_of_factorial_of_digits(n) == n) {
cout << "The sum of the factorials of the digits is equal to the number" << endl;
} else {
cout << "The sum of the factorials of the digits is NOT equal to the number" << endl;
}
return 0;
}
/*
OUTPUT -
Enter a number: 121
The sum of the factorials of the digits is NOT equal to the number
*/
#include<stdio.h>
int main(){
int num,a=0,b=1,i,next;
scanf("%d",&num);//Lenghth of the series
printf("%d\n%d\n",a,b);//0 1
//We have to print num-2=3
for(i=1;i<num;i++){
next=a+b; //next=0+1=1
a=b; //a=1
b=next; //b=1
printf("%d\n",next);
}
}
/*
OUTPUT
5
0
1
1
2
3
5
*/




Popular Category
Hot Topics
Go through our study material. Your Job is awaiting.