answersLogoWhite

0


Best Answer

i have solved this problem.....!! i dont know that my Program is fastest than other traditional algos like prime swing etc. MY computer computed factorial of 123456! in appx 14-15 mins. The output was of 5,74,965 digits. actually no computer in this world can support this big answer.

Actually i saved my ans into an array. My program is in C. If any body really interested to see the result & program logic, then contact me at ankitsingh.05@gmail.com.

Regards,

Ankit Singh

Pune

User Avatar

Wiki User

16y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the fastest way to compute the factorial of 123456 on a processor of speed 1.4 Ghz 512 mb ram and 40 gb hard disk?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are the parts of Visual basic.net?

Visual basic is a programming language from Microsoft. Some of its parts include data access objects, ActiveX data objects, and remote data objects. Their function is to provide access to databases.


C program to print inverse of a given number?

Inversing of a given Number. suppose we gave input 123456 then the output of the program will be 654321./*mycfiles.wordpress.comC program to print inverse of a given number*/#include#includevoid main(){long int n,rn=0,d=0;clrscr();printf("Enter the number\n\n");scanf("%ld",&n);while(n>0){d=n%10;rn=rn*10+d;n=n/10;}printf("%ld",rn);getch();}


What is the code for the following program 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15?

#include <stdio.h> int main (int argc, char **argv) { printf ("1 1 2 1 1 2 1 3 1 2 1 1 2 1 3 1 2 1 4 1 2 1 3 1 2 1\n"); }


How many 3-digit numbers can be formed using the digit 123456 and 7 if no digit can be repeated in number?

With questions like these it is often difficult to remember whether we are looking for permutations or combinations. In English we use these two terms interchangeably but in mathematics we must be more precise. The way to remember is that if the order matters, then position matters, thus position = permutation. If order does not matter then we're looking for combinations. Put simply, 123 and 321 are the same combination but different permutations. In this case we're looking for permutations (thus combination locks should really be called permutation locks).The formula for calculating permutations is fairly simple: given 7 digits from which we must select 3, we have 7^3 = 7 x 7 x 7 = 343 permutations in total. However, in order to exclude repeated digits we must use a different formula. When we select the first digit we have 7 choices (just as we do with repetition allowed), but when we choose the next digit we only have 6 choices remaining and for the final digit we only have 5 choices remaining.To express this more mathematically, we need to use factorials. Factorial 7 (written 7!) is 7 x 6 x 5 x 4 x 3 x 2 x 1 = 5040. This tells us there are 5040 different ways we can write all the digits from 1 to 7 without repetition. In order to calculate all the 3-digit permutations we need to stop multiplying when we reach 4. To achieve this, we use the following formula:n! / (n-m)!where n is the number of elements in the set and m is the number of elements we wish to select.Thus we get:7! / (7-3)! = 7! / 4!If we (partially) expand this we find we have:7 x 6 x 5 x 4! / 4!The 4!s above and below the division will cancel each other out, so we get:7 x 6 x 5 = 210 permutations without repetition.If we were to fully expand this out we find we have:(7 x 6 x 5 x 4 x 3 x 2 x 1) / (4 x 3 x 2 x 1) = 5040 / 24 = 210 permutations without repetition.Note that if we were only interested in the number of combinations (without repetition), we divide the number of permutations by 3! For that we use the following formula instead:n! / (m! x (n-m)!)Thus we'd get:7! / (3! x 4!) = (7 x 6 x 5 x 4!) / (3 x 2 x 1 x 4!)The 4!s cancel each other out so we get:(7 x 6 x 5) / (3 x 2 x 1) = 210 / 6 = 35 combinations without repetition.


How do you reverse a 6 digit number in C plus plus?

The number of digits is immaterial, the principal is exactly the same. The key to reversing any number is in the following user-defined function: uint reverse(uint num) { uint rev=0; while(num) { rev*=10; rev+=num%10; num/=10; } return(rev); } The following code demonstrates how to reverse a 6 digit number entered from the console. #include<iostream> #include<string> #include<sstream> typedef unsigned int uint; uint reverse(uint num) { uint rev=0; while(num) { rev*=10; rev+=num%10; num/=10; } return(rev); } int getrange(uint digits,uint& min,uint&max) { if(!digits) return(-1); min=1; while(--digits) min*=10; max=min*10-1; return(0); } uint inputnumber(const std::string prompt,const uint min,const uint max) { using namespace std; uint result=0; while(1) { cout<<prompt; string s; getline(cin,s); if(s.size()) result=stoul(s,0,10); if(result<min result>max) cout<<"The number must be in the range " <<min<<".."<<max<<"\n" <<"Please enter another number.\n"<<endl; else break; } return(result); } uint inputnumber(const uint digitcount) { using namespace std; uint min=0, max=0; if(getrange(digitcount,min,max)==-1) return(0); std::stringstream prompt; prompt<<"Enter a "<<digitcount<<" digit number: "; return(inputnumber(prompt.str(),min,max)); } int main() { using namespace std; uint num=inputnumber(6); // 6 digits. if(num) { uint rev=reverse(num); cout<<"Reverse: "<<rev<<"\n"<<endl; } return(0); } Output: Enter a 6 digit number: 123456 Reverse: 654321