![]() |
|
|
#1 |
|
Nov 2004
24 Posts |
I need to see if big numbers, for instance greater than 10^12, are integers? VB6, C++ and the others don't offer this possibility. Could you indicate me some useful programs? Thanks.
|
|
|
|
|
|
#2 | |
|
Jul 2005
2×193 Posts |
Quote:
In the mean time I guess you need to take a look at GMP http://www.swox.com/gmp It's a multi-precision maths library that you can use from C++. |
|
|
|
|
|
|
#3 |
|
"Richard B. Woods"
Aug 2002
Wisconsin USA
22×3×641 Posts |
Perhaps Crook is referring to, for example, determining whether the result of 123456789012345678901234567890123456789^0.5 is an integer.
Last fiddled with by cheesehead on 2005-11-24 at 19:38 |
|
|
|
|
|
#4 | |
|
Jun 2005
2·191 Posts |
Quote:
Drew |
|
|
|
|
|
|
#5 | |
|
Jul 2005
2·193 Posts |
Quote:
With GMP the above is simple:- Code:
int main(void) {
mpz_t orig, sqrt, square;
mpz_init( orig );
mpz_init( sqrt );
mpz_init( square );
mpz_set_str( orig, "123456789012345678901234567890123456789", 10 );
mpz_sqrt( sqrt, orig );
mpz_mul( square, sqrt, sqrt );
if( mpz_cmp( square, orig ) == 0 ) {
gmp_printf( "%Zd is %Zd^2\n", orig, sqrt );
} else {
gmp_printf( "%Zd is not a square\n", orig );
}
return(0);
}
|
|
|
|
|
|
|
#6 |
|
Nov 2004
208 Posts |
I need to verify, for instance, if (17^64-1)/24 is an integer. Just an example. Does GMP provide me this feature?
|
|
|
|
|
|
#7 |
|
Jul 2005
2·193 Posts |
Yes GMP can do it, but it isn't necessary.
Here's a good explanation of some tricks that can help you. http://mathforum.org/library/drmath/view/55889.html Once you've read that consider this: If you are checking whether (17^e)-1 is divisible by 24 then consider this: 17 mod 24 = 17 (17*17) mod 24 = 1 Therefore (17*17)-1 mod 24 = 0 and so (17^2)-1 is divisible by 24. (17^2) * 17 mod 24 = 1 * 17 mod 24 = 17 mod 24. (17^3) * 17 mod 24 = 17 * 17 mod 24 = 1 mod 24. So all even n for (17^n)-1 are divisible by 24. |
|
|
|
|
|
#8 |
|
∂2ω=0
Sep 2002
República de California
5·17·137 Posts |
For numbers < 10000 digits or so and where one only needs to check a smallish number of instances, there's little point in spending time writing a custom GMP-based app - any halfway-decent "abritrary-precision" calculator (e.g. Unix/linux bc, mathematica, PARI) will serve for these kinds of things. I have PARI installed on my windows PC (it's a simple precompiled-binary download) and use it all the time. For certain things (e.g. binary and hex-format I/O) I find Unix bc more convenient.
|
|
|
|
|
|
#9 | |
|
Bamboozled!
"𒉺𒌌𒇷𒆷𒀭"
May 2003
Down not across
47×229 Posts |
Quote:
I use bc or "bc -l" for most of my simple arithmetic and Pari/gp for anything more complicated, such as modular inverses or simple polynomial manipulation. bc -l is good for units conversion (I very often need to convert seconds to hours or days) and for estimating sizes of integers in bits or digits. When I want a decent approximation to pi(x) I invariably use bc to calculate x/(l(x)-1) rather than fire up something heavyweight to obtain an exact answer. If I have a small integer to factor, up to 40 or 50 digits say, it is often quicker to ask Pari/gp than to fire up a dedicated factoring program. Paul |
|
|
|
|
|
|
#10 |
|
Jun 2007
Moscow,Russia
7×19 Posts |
If need to check k | a^b-c for positive integers k,a,b,c
using Mathematica -just evaluate PowerMod[a,b,k]==c If result is True, k divides a^b-c , otherwise - doesn't. Last fiddled with by VolMike on 2007-06-08 at 12:20 |
|
|
|
|
|
#11 | |
|
∂2ω=0
Sep 2002
República de California
5×17×137 Posts |
Quote:
4*a(1) If I need more than the default number of digits, I preface that with scale = {how many digits I need} |
|
|
|
|
![]() |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Basic Number Theory 10: complex numbers and Gaussian integers | Nick | Number Theory Discussion Group | 8 | 2016-12-07 01:16 |
| self-verify (tripplecheck on same machine) | TheJudger | PrimeNet | 12 | 2011-05-11 11:02 |
| Verify Accuracy of Test | Numbers | PrimeNet | 8 | 2005-07-31 08:16 |
| Program to verify factors | HiddenWarrior | LMH > 100M | 5 | 2005-04-18 09:00 |
| How do we verify Factoring Work? | E_tron | Math | 4 | 2003-12-10 05:08 |