Ask Your Question
0

How do I convert a 300-digit number to scientific notation?

asked 2016-09-01 03:08:39 +0200

sagemath1993 gravatar image
a=300
P0= next_prime(10^a)
print( ' p0 is 10^{} + {}'.format(a, P0 - 10^a) );
P1 = next_prime(P0)
print( ' p1 is 10^{} + {}'.format(a, P1 - 10^a) );
P2 = next_prime(P1)
print( ' p2 is 10^{} + {}'.format(a, P2 - 10^a) );

F=GF(P0)
g=F(10)
h=g^(-1)
print h;
print h*g;

With this code, I get a massive number for h and 1 for h*g as desired. How can I convert h to scientific notation (in this case, 90000000...000298 = 9 x 10^ + 298?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-09-01 05:17:48 +0200

updated 2016-09-01 06:05:08 +0200

Since taking logarithms of large numbers is very slow, here's a faster way. First transform h to a SageMath integer, then evaluate the parts of the number individually:

hInt = ZZ(h)
exp = hInt.ndigits() - 1
mult = int( hInt / 10^exp )
rem = hInt - mult * 10^exp

print "h is {} x 10^{} + {}".format( mult, exp, rem )

Here's a live example with just the calculation of P0 and h.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-09-01 03:08:39 +0200

Seen: 915 times

Last updated: Sep 01 '16