Ask Your Question
1

Displaying large prime numbers as 10^a + x?

asked 2016-08-24 18:40:27 -0500

sagemath1993 gravatar image

updated 2016-08-24 19:09:55 -0500

I just started using SAGE and I wanted to display my large prime numbers as 10^a + x, rather than it having it spit out a ton of zeros.

So far my code looks like

  a=100;
P= next_prime(10^a);
next_prime(P)
next_prime(P)- next_prime(10^a);

With this, it outputs the very large number and while I know how to write it down as 10^a + x (in this case, 10^100 + 949), how do I add that to the code so it would display it like that?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-08-24 20:12:37 -0500

updated 2016-08-24 20:27:17 -0500

One simple way is to use a formatted Python string like

'10^{} + {}'.format(a,difference)

Here's some code that prints the decomposition of the first five primes above 10^a:

a = 100
p = 10^a

for i in range(0,5):
    p = next_prime(p)
    print( '10^{} + {}'.format(a, p - 10^a) )

and here's a live example.

edit flag offensive delete link more

Comments

Thank you! It seems my code is displaying the 2nd prime and the difference between the 2nd and 1st prime after 10^a instead of displaying the first prime after 10^a

sagemath1993 gravatar imagesagemath1993 ( 2016-08-24 20:43:09 -0500 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2016-08-24 18:40:27 -0500

Seen: 42 times

Last updated: Aug 24 '16