Computer Science Canada factorial powers program problems |
Author: | Chimaera [ Sun Nov 30, 2003 5:46 pm ] | ||
Post subject: | factorial powers program problems | ||
I'm having problems with finding the correct number of zeros from the furthest right non zero digit and also turing doesn't allow me to save the value of the factorial of the number once I go past 12, is there any way I can solve these problems with the program? Thanks
|
Author: | Mazer [ Sun Nov 30, 2003 10:23 pm ] | ||
Post subject: | |||
i don't really understand what the problem is with the factorials, but i think i can help with the nonzero number thing. from what i see what you're trying to do is check if there is one zero, then if there are two zeroes, and so on. the problem with that is that it's really inefficient and if you had a number like 10 trillion (which is too big but oh well) things would get ugly. you should make a function that: -takes an int -converts it to a string -then goes through the string backwards until it doesn't find a zero -converts that part of the string back to an integer -return the integer this should do it:
|
Author: | Chimaera [ Mon Dec 01, 2003 1:56 pm ] |
Post subject: | |
the problem with the factorials is that the numbers is causing an integer overflow, I need a way to convert the integer to string while saving the value of the num! |
Author: | Blade [ Mon Dec 01, 2003 2:36 pm ] |
Post subject: | |
strint(var:string) -> string to integer function intstr(var:int) -> integer to string funtion |
Author: | Andy [ Mon Dec 01, 2003 4:26 pm ] |
Post subject: | |
we had a problem similar to this with the last dwite. i would do what blade said and use strint. and when u are multiplying a new number on, use the steps of how you would multiply by hand and manipulate the string character by character |
Author: | bugzpodder [ Mon Dec 01, 2003 5:18 pm ] |
Post subject: | |
i cant program in turing anymore so i'll do it straight C++ num1=num; while(num1>0) {num1/=5; cnt1+=num1;} num1=num; while(num1>0) {num1/=2; cnt2+=num1;} num2=1; for (i=0;i<cnt2-cnt1;cnt++){ num2=(num2*2)%10;} for (j=1;j<=num;j++) {num1=j; while(num1%2==0) num1/=2; while(num1%5==0) num1/=5; num2=(num2*num1%10)%10; } cout<<"The right most non-zero digit is "<<num2<<" and it is followed by "<<cnt1<<"zeros!!"<<endl; |
Author: | Andy [ Mon Dec 01, 2003 6:25 pm ] | ||
Post subject: | |||
and i'll translate that
wow... so much more complicated in turing |
Author: | bugzpodder [ Mon Dec 01, 2003 6:40 pm ] |
Post subject: | |
copycat!! |
Author: | Andy [ Mon Dec 01, 2003 6:41 pm ] |
Post subject: | |
jack, this is in the turing help section... i dont think the kids who ask for help know c++... thats why i said i translated yours? |
Author: | bugzpodder [ Mon Dec 01, 2003 8:33 pm ] |
Post subject: | |
sheesh, stop spamming already... geez people these days? how many bits do you need man do something useful and explain your program if you think you are so useful? I purposely did NOT write Turing code! the idea is to learn from the code, NOT COPY AND PASTE~ do you think that I cant program in turing? |
Author: | Mazer [ Mon Dec 01, 2003 8:45 pm ] |
Post subject: | |
bugzpodder wrote: do you think that I cant program in turing?
now where would dodge get a crazy idea like that ![]() bugzpodder wrote: i cant program in turing anymore |
Author: | Andy [ Mon Dec 01, 2003 8:47 pm ] |
Post subject: | |
exactly... u said it not me |
Author: | Chimaera [ Tue Dec 02, 2003 9:45 pm ] |
Post subject: | |
ya this question was from a 1995 programming competition and my teacher said it was a very common problem for programmers because often they have to deal with numbers that're out of range for their integers, reals etc. etc. So they have to devise a solution which is sort of similar to what I'm trying to do here... |