Posts

Digits in Factorial

Problem Statement:   Given an integer   N . The task is to find the number of digits that appear in its factorial, where factorial is defined as, factorial(n) = 1*2*3*4……..*N and factorial(0) = 1. Example 1: Input: N = 5 Output: 3 Explanation: Factorial of 5 is 120. Number of digits in 120 is 3 (1, 2, and 0) Example 2: Input: N = 120 Output: 199 Explanation: The number of digits in 200! is 199 Your Task: You don't need to read input or print anything. Your task is to complete the function  digitsInFactorial()  that takes  N  as parameter and returns  number of digits  in factorial of  N . Expected Time Complexity  : O(N) Expected Auxilliary Space  : O(1) Constraints: 1 ≤ N ≤ 10 4  The link of this problem is  https://practice.geeksforgeeks.org/problems/digits-in-factorial/1 Solution: Python3 import math def digitsInFactorial(N):     sum1=0     for i in range(1,N+1):         sum1+=math.log10(i)     return math.floor(sum1)+1 def main():     T=int(input())     while(T>0):         N

Sum of Prime

Problem Statement :   Given a number (greater than 2), print two prime numbers whose sum will be equal to given number, else print -1 if no such number exists. NOTE :  A solution will always exist if the number is even. If [a, b] is one solution with a <= b, and [c, d] is another solution with c <= d, and a < c then print [a, b] only and not all possible solutions. Input: The first line contains an integer  T , depicting total number of test cases. Then following T lines contains an integer N. Output: Print the two prime numbers in a single line with space in between. Constraints: 1 ≤ T ≤ 50 2 ≤ N ≤ 1000000 Example: Input : 2 8 3 Output 3 5 -1 Explanation: Testcase 1:  two prime numbers from 1 to 8 are 3 and 5 whose sum is 8. This problem is available in Geeksforgeeks, the link of which is mentioned below. https://practice.geeksforgeeks.org/problems/sum-of-prime/0 Solution: CPP Solution #include<iostream> using namespace std; //Function to determine whether a number is p