Ask Your Question

# Displaying large prime numbers as 10^a + x?

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 close merge delete

## 1 Answer

Sort by » oldest newest most voted

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.

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

## Your Answer

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

Add Answer

## Stats

Asked: 2016-08-25 01:40:27 +0200

Seen: 115 times

Last updated: Aug 25 '16