ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 18 Oct 2014 11:09:42 -0500Divisibilityhttps://ask.sagemath.org/question/24521/divisibility/To find numbers of the form 7aaa that are multiples of 7, I use:
sage:print [a for a in [0..9] if (7000+111*a)%7==0]
[0, 7]
I do not know how to write for 7|7abc.
Thanks.Sat, 18 Oct 2014 10:32:22 -0500https://ask.sagemath.org/question/24521/divisibility/Comment by masac for <p>To find numbers of the form 7aaa that are multiples of 7, I use:</p>
<pre><code>sage:print [a for a in [0..9] if (7000+111*a)%7==0]
[0, 7]
</code></pre>
<p>I do not know how to write for 7|7abc.</p>
<p>Thanks.</p>
https://ask.sagemath.org/question/24521/divisibility/?comment=24524#post-id-24524Thank you for edit.Sat, 18 Oct 2014 10:48:27 -0500https://ask.sagemath.org/question/24521/divisibility/?comment=24524#post-id-24524Comment by vdelecroix for <p>To find numbers of the form 7aaa that are multiples of 7, I use:</p>
<pre><code>sage:print [a for a in [0..9] if (7000+111*a)%7==0]
[0, 7]
</code></pre>
<p>I do not know how to write for 7|7abc.</p>
<p>Thanks.</p>
https://ask.sagemath.org/question/24521/divisibility/?comment=24523#post-id-24523I reedit your question. Please double check that it is all right. It was not very clear.Sat, 18 Oct 2014 10:45:49 -0500https://ask.sagemath.org/question/24521/divisibility/?comment=24523#post-id-24523Answer by masac for <p>To find numbers of the form 7aaa that are multiples of 7, I use:</p>
<pre><code>sage:print [a for a in [0..9] if (7000+111*a)%7==0]
[0, 7]
</code></pre>
<p>I do not know how to write for 7|7abc.</p>
<p>Thanks.</p>
https://ask.sagemath.org/question/24521/divisibility/?answer=24526#post-id-24526 I tried:
sage: a=range(7000,8000)
sage: print[a if a%7==0]
File "<ipython-input-30-590163f2a51e>", line 1
print[a if a%Integer(7)==Integer(0)]
^
SyntaxError: invalid syntax
I find a solution:
print [a for a in [7000..7999] if a%7==0]
Thank you for support.
Sat, 18 Oct 2014 11:09:42 -0500https://ask.sagemath.org/question/24521/divisibility/?answer=24526#post-id-24526Answer by vdelecroix for <p>To find numbers of the form 7aaa that are multiples of 7, I use:</p>
<pre><code>sage:print [a for a in [0..9] if (7000+111*a)%7==0]
[0, 7]
</code></pre>
<p>I do not know how to write for 7|7abc.</p>
<p>Thanks.</p>
https://ask.sagemath.org/question/24521/divisibility/?answer=24525#post-id-24525Hello,
There are various solutions. To generate the list of numbers of the form 7abc, you can use one of:
sage: numbers0 = range(7000,8000)
sage: numbers1 = [7000 + x for x in range(1000)]
sage: numbers2 = [7000 + a*100 + b*10 + c for a in range(10) for b in range(10) for c in range(10)]
Then you can check divisibility the very same way you did. But note that there is a faster way since x is a multiple of **7** if and only if **x+7** is a multiple of 7. So once you find one, you only need to go 7 by 7.
Is that ok ?
VincentSat, 18 Oct 2014 10:51:02 -0500https://ask.sagemath.org/question/24521/divisibility/?answer=24525#post-id-24525