Three mirrors are arranged in the shape of an equilateral triangle, with their reflective surfaces pointing inwards. There is an infinitesimal gap at each vertex of the triangle through which a laser beam may pass.
Label the vertices A, B and C. There are 2 ways in which a laser beam may enter vertex C, bounce off 11 surfaces, then exit through the same vertex: one way is shown below; the other is the reverse of that. see the image here Image
There are 80840 ways in which a laser beam may enter vertex C, bounce off 1000001 surfaces, then exit through the same vertex.
In how many ways can a laser beam enter at vertex C, bounce off 12017639147 surfaces, then exit through the same vertex?
import fractions
surf = 12017639147
row = (surf + 3)/2
offset = 3 - (row %3)
col = offset
row -= offset
total = 0
while row > col:
if fractions.gcd(row,col) == 1:
total += 1
row -= 3
col += 3
if row %1000000 == 0:
print (total)
print (total * 2)
This solution is taking a long time.How to do it in lesser time?
Aucun commentaire:
Enregistrer un commentaire