Ask Your Question
1

Displaying large prime numbers as 10^a + x?

asked 2016-08-25 01:40:27 +0100

sagemath1993 gravatar image

updated 2016-08-25 02:09:55 +0100

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-25 03:12:37 +0100

updated 2016-08-25 03:27:17 +0100

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-25 03:43:09 +0100 )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-25 01:40:27 +0100

Seen: 314 times

Last updated: Aug 25 '16