# Cryptographic Mathematics

Anonymous

Q: Programme Rowland’s formula and verify his results. Try different starting values and see what happens.

In Sage math cloud, I did this:

i =7
n=2
for n in [1..10]:
i=i+gcd(n,i)
print i


edit retag close merge delete

i=7 n=2 for n in range(2,100): i=i+gcd(n,i) print i

( 2016-10-01 23:04:16 +0100 )edit

Sort by » oldest newest most voted

Update:

i=7
n=2
for n in range(2,100):
i=i+gcd(n,i)
print i

more

• as i told before, the second line is useless
• the Rowland sequence is not the list of i but i-iold.
• you will get a lot of 1, so instead of printing them, you should only print the i-iold that are different from 1, use an if statement.
• actually, your loop should go to 1000 or even 10000 (which makes sense only if you ignore the 1, or you won't see anything).
( 2016-10-02 00:05:06 +0100 )edit

Here are some hints:

• please re-read Rowland's formula, the interesting sequence is not $a(n)$ but the first difference $a(n)-a(n-1)$,
• If you want to see some primes appearing (not only 1's), you should look for more than only the first 10 values,
• the line n=2 is useless since it is erased by the next loop, if you want to start at n=2 your loop should look like : for n in range(2,100):,
• what is inside your loop should be indented
• to verify the formula, you should make a test that discards the 1's appearing, and that check and prints the other if they are prime (and raise/print an error message if not).
more

could you please post the code of Sage?

( 2016-10-01 21:36:54 +0100 )edit

Your code is a good start, so you should get a correct code from my remarks (i updated it to be more precise). Please do not hesitate to provide some new attempts and ask for comments.

( 2016-10-01 21:42:44 +0100 )edit

i=7 n=2 for n in range(2,100): i=i+gcd(n,i) print i

( 2016-10-01 23:02:34 +0100 )edit