473,899 Members | 4,299 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Number of digits in N!

Hello.

Is there a method for computing the number of digits, in a given numeric
base, of N factorial, without actually computing the factorial?

For example, 8! has 5 digits in base 10; 10! has 7 digits in base 10.
Is there a way to compute that information without actually evaluating
the factorial?
Oct 5 '06
109 7664

"Jon Slaughter" <Jo***********@ Hotmail.comwrot e in message
news:12******** *****@corp.supe rnews.com...
>
"Pascal Bourguignon" <pj*@informatim ago.comwrote in message
news:87******** ****@thalassa.i nformatimago.co m...
>"Jon Slaughter" <Jo***********@ Hotmail.comwrit es:
>>"Pascal Bourguignon" <pj*@informatim ago.comwrote in message
news:87****** ******@thalassa .informatimago. com...
"Proginoskes " <CC*******@gmai l.comwrites:
Which I did. Again, the number 3,628,800 does not appear anywhere in
my
calculation s. Therefore, I calculated the number 7 "without computing
the factorial".

Of course you did! "6.55976303 3" and "3,628,800" and "3628800" are
representati ons for the same number, "factorial of ten". The first is
a written representation of the number on the logarithmic scale, while
the others are different representations of the number on linear
scales. But they're both but _representation s_ for the same number.
lol. then whats the point. With your definition all numbers have the
same
representatio n.
i.e., there is only one number... why might as well call it 0.
i.e., its very easy to transform any number into another number and by
your
definition if there exists such a transform then they must be
equivilent.

If you can find an isomorphism between the structures of these
transforms and the set of numbers you consider, yep.

But an isomorphism always exist. Or, atleast an isometry. y = ax + b and
even y = b are simple isomorphism in a group(and hence a ring and field)
that let you get all the other elements.

f(x) = ax + b;

hence f(x + y) = a*(x+y) + 2b = a*x + b + a*y + b = f(x) + f(y)

hence f(x) is a homeomorphism and its obvious thats its an isomorphism.
I don't think the topological content of the problem relevant and would
think that homeo- is properly homo- . That's a very faggy thing to say, so
I'll anounce that I'm shutting off my computer to go out and look for a girl
who looks like Dean Neuman's daughters. EC
Oct 14 '06 #101
Chris wrote:
) Willem wrote:
)Logan wrote:
)) Any given integer can be represented in a finite number of bits. The
)) same is not true for any particular given logarithm. Some of them
)) (such as log2(256)) can be represented in a finite number of bits, but
)) some of them cannot.
)>
)Well, you can't even represent 1/3 in a finite number of bits, then.
)
) Sure you can: with a `ratio` object with numerator 1 and denominator 3:

In that case you can also represent any given logarithm in a finite number
of bits. I didn't end my sentence above with 'then' for nothing you know.
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Oct 14 '06 #102
Willem wrote:
Logan wrote:
) Any given integer can be represented in a finite number of bits.
....
Well, you can't even represent 1/3 in a finite number of bits, then.
1/3 is not an integer.
Oct 14 '06 #103
jmcgill said:
Willem wrote:
>Logan wrote:
) Any given integer can be represented in a finite number of bits.
...
>Well, you can't even represent 1/3 in a finite number of bits, then.

1/3 is not an integer.
It's actually an int, with the value 0 - integer division, remember! :-)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Oct 14 '06 #104
Willem wrote:
Logan wrote:
) Any given integer can be represented in a finite number of bits. The
) same is not true for any particular given logarithm. Some of them
) (such as log2(256)) can be represented in a finite number of bits, but
) some of them cannot.

Well, you can't even represent 1/3 in a finite number of bits, then.
Sure you can. For example, in ASCII, it's "1/3". That's 24 bits.

:)

--
Clark S. Cox III
cl*******@gmail .com
Oct 14 '06 #105
Clark S. Cox III wrote:
Willem wrote:
>Logan wrote:
) Any given integer can be represented in a finite number of bits. The
) same is not true for any particular given logarithm. Some of them
) (such as log2(256)) can be represented in a finite number of bits, but
) some of them cannot.

Well, you can't even represent 1/3 in a finite number of bits, then.

Sure you can. For example, in ASCII, it's "1/3". That's 24 bits.

:)
#include <stdio.h>
int main(void) {
char a[] = "1/3";
printf("%d\n", (int)sizeof a);
return 0;
}
...says 4 which is 32 bits, right?

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Oct 14 '06 #106

On Sat, 14 Oct 2006, Joe Wright wrote:
Clark S. Cox III wrote:
>Willem wrote:
>>Logan wrote:
) Any given integer can be represented in a finite number of bits. The
) same is not true for any particular given logarithm. Some of them
) (such as log2(256)) can be represented in a finite number of bits, but
) some of them cannot.

Well, you can't even represent 1/3 in a finite number of bits, then.

Sure you can. For example, in ASCII, it's "1/3". That's 24 bits.

#include <stdio.h>
int main(void) {
char a[] = "1/3";
printf("%d\n", (int)sizeof a);
return 0;
}
..says 4 which is 32 bits, right?
(Oh boy, crossposts to c.l.c that assume CHAR_BIT==8! ;)
I think your compiler needs some helpful hints. Try

#include <stdio.h>
int main(void) {
char a[3] = "1/3";
printf("%d\n", (int)sizeof a);
return 0;
}

/* ;-) */

-Arthur
Oct 15 '06 #107
Logan Shaw wrote:
No, the straightforward algorithm involves only rational numbers (which
can be represented with a finite amount of information) and thus never
needs to suffer from rounding errors. The log-based one must suffer from
rounding errors since it involves irrational numbers (which require an
infinite amount of information to be represented directly).
Reading this subthread, I get the strong impression that many people have
never heard of the notion of computable reals. Search the web for "exact
real arithmetic" or "computable real arithmetic" and you'll find many
libraries that will let you compute (sum_{i=1}^{N} log i) without roundoff
just as easily as GMP lets you compute (prod_{i=1}^{N} i) without wraparound.

-- Ben
Oct 15 '06 #108
Ben wrote:
) Reading this subthread, I get the strong impression that many people have
) never heard of the notion of computable reals. Search the web for "exact
) real arithmetic" or "computable real arithmetic" and you'll find many
) libraries that will let you compute (sum_{i=1}^{N} log i) without roundoff
) just as easily as GMP lets you compute (prod_{i=1}^{N} i) without wraparound.

Well then, just for the sake of argument, and keeping the OP in mind:

How exactly would such a library compute log10(7)+log10( 8) ?
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
Oct 15 '06 #109

jmcgill wrote:
Hello.

Is there a method for computing the number of digits, in a given numeric
base, of N factorial, without actually computing the factorial?

For example, 8! has 5 digits in base 10; 10! has 7 digits in base 10.
Is there a way to compute that information without actually evaluating
the factorial?
I just found a formula in a book that might produce a very good
algorithm:

log(n!) = sum([n/p^k]*log(p))

where the sum runs over all p^k <= n and [ ] is the floor function.
This does require you to know all primes up to n though but this could
be in a lookup table.

so log(6!) = log(2)*([6/2] + [6/2^2]) + log(3)*[6/3] + log(5)*[6/5]

Ofcourse this sum isn't much different than sum(log(k),k=2. .6) = log(2)
+ log(3) + log(4) + log(5) + log(6) for small n but might be pretty
good for large n since these primes are not very dense in the integers.

Anyways, I thought I'd throw it out there as its quite an interesting
formula.

Jon

Oct 19 '06 #110

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2996
by: jose luis fernandez diaz | last post by:
Hi, My OS is: cronos:jdiaz:tmp>uname -a HP-UX cronos B.11.11 U 9000/800 820960681 unlimited-user license I compile in 64-bits mode the program below:
1
3882
by: Shreyas Kulkarni | last post by:
hi there, recently i have got a problem regarding calculation of sum of digits in a floating point or precision number. the weird behaviour of compiler/language is preventing me from calculating the sum of all digits. the compiler doesnt store the number as given by the user. some of the precision digits are lost or changed (at will!). so by any method, i m unable to reliably calculate the sum of provided number; except i input the...
10
4252
by: guidosh | last post by:
Hello, I'm trying to write a printf statement that sets the field width when printing a number. I'm using this: printf("%*", fieldwidth, num_to_print); However, I can't figure out how to get the number of digits in the number (which I would then assign to the 'fieldwidth' variable above).
6
7376
by: Jovo Mirkovic | last post by:
Hi, I have to make a program which will generate 100,000 different ID numbers (for example 2345-9341-0903-3432-3432 ...) It must be really different, I meen it can not be a similar (like 2345-9341-0903-3432-343<b>1</b>) Does exist some algorithm for that... Thanks.
27
31389
by: Luke Wu | last post by:
Is there a C function that returns the number of digits in an input int/long? example: numdigits(123) returns 3 numdigits(1232132) returns 7
23
9820
by: neha_chhatre | last post by:
which is the best format specifier(data type) if i have to work with decimal number. also please tell me the syntax for truncating a decimal number please reply as soon as possible
20
5038
by: jacob navia | last post by:
Hi "How can I round a number to x decimal places" ? This question keeps appearing. I would propose the following solution #include <float.h> #include <math.h>
0
22499
by: zephyrus360 | last post by:
This is about a technique to find the mod of a very large integer with a normal small integer. I recently encountered this problem when I needed to compute the modulus of a very large number with a normal integer. I needed this in a C++ program running on a 32-bit UNIX platform. The problem was that the number was 28 digits long and no native datatype in c++ could store a number of that size. (Eg: 1088263455689473669888943602 % 380) Not...
1
3627
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent via an email function. But just can't figure it out. <? //////////////////////////////////////////////////////////// //
0
9997
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9845
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11276
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10866
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5891
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4721
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3320
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.