ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 24 Aug 2016 20:43:09 -0500Displaying large prime numbers as 10^a + x?http://ask.sagemath.org/question/34574/displaying-large-prime-numbers-as-10a-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?Wed, 24 Aug 2016 18:40:27 -0500http://ask.sagemath.org/question/34574/displaying-large-prime-numbers-as-10a-x/Answer by paulmasson for <p>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.</p>
<p>So far my code looks like </p>
<pre><code> a=100;
P= next_prime(10^a);
next_prime(P)
next_prime(P)- next_prime(10^a);
</code></pre>
<p>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?</p>
http://ask.sagemath.org/question/34574/displaying-large-prime-numbers-as-10a-x/?answer=34575#post-id-34575One 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](http://sagecell.sagemath.org/?z=eJxLVLBVMDQw4OUqADPiEnm5eLnS8osUMhUy8xSKEvPSUzUMdEw1rXi5FIAApCovtaIkvqAoMzdVo0ATKlyUmVeioaAONKC6VkFbobpWXQ9oSG5iiUaiDlCTLthoTQWgcgA_jxzY&lang=sage).Wed, 24 Aug 2016 20:12:37 -0500http://ask.sagemath.org/question/34574/displaying-large-prime-numbers-as-10a-x/?answer=34575#post-id-34575Comment by sagemath1993 for <p>One simple way is to use a formatted Python string like</p>
<pre><code>'10^{} + {}'.format(a,difference)
</code></pre>
<p>Here's some code that prints the decomposition of the first five primes above <code>10^a</code>:</p>
<pre><code>a = 100
p = 10^a
for i in range(0,5):
p = next_prime(p)
print( '10^{} + {}'.format(a, p - 10^a) )
</code></pre>
<p>and here's a <a href="http://sagecell.sagemath.org/?z=eJxLVLBVMDQw4OUqADPiEnm5eLnS8osUMhUy8xSKEvPSUzUMdEw1rXi5FIAApCovtaIkvqAoMzdVo0ATKlyUmVeioaAONKC6VkFbobpWXQ9oSG5iiUaiDlCTLthoTQWgcgA_jxzY&lang=sage">live example</a>.</p>
http://ask.sagemath.org/question/34574/displaying-large-prime-numbers-as-10a-x/?comment=34576#post-id-34576Thank 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^aWed, 24 Aug 2016 20:43:09 -0500http://ask.sagemath.org/question/34574/displaying-large-prime-numbers-as-10a-x/?comment=34576#post-id-34576