Advertisement
Guest User

temaC1

a guest
Dec 11th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. # Hello World program in Python
  2. import math
  3.  
  4. def modulo(x, n):
  5.     if x % n > (n//2):
  6.         return int((x % n) - n)
  7.     else:
  8.         return int(x % n)
  9.        
  10. def factors(n):
  11.     a = []
  12.     i = 2
  13.  
  14.     while True:
  15.  
  16.       c = 0
  17.  
  18.       while n % i == 0:
  19.             c = c + 1
  20.             n = n / i
  21.  
  22.       if c != 0:
  23.          a.append([i,c])
  24.      
  25.       i = i + 1
  26.  
  27.       if n == 1:
  28.          break    
  29.     return a
  30.  
  31.  
  32.  
  33. def compute_table(m):
  34.     b_1 = 1
  35.     a = []
  36.     a0 = b0 = int(math.sqrt(m))
  37.     x0 = math.sqrt(m) - int(math.sqrt(m))
  38.     b_patrat = modulo(b0*b0, m)
  39.     a.append({"a":a0, "b":b0, "x":x0, "b^2":b_patrat})
  40.    
  41.     a1 = int(1/x0)
  42.     x1 = 1/x0 - a1
  43.     b1 = a1*b0 + b_1
  44.     b1_patrat = modulo(b1*b1, m)
  45.     a.append({"a":a1, "b":b1, "x":x1, "b^2":b1_patrat})
  46.  
  47.     for i in range(2,16):
  48.         ai = int(1/a[i-1]["x"])
  49.         xi = 1/a[i-1]["x"] - ai
  50.         bi = ((ai*a[i-1]["b"] + a[i-2]["b"]) % m)
  51.         bi_patrat = modulo(bi*bi, m)
  52.         a.append({"a":ai,"b":bi,"x":xi,"b^2":bi_patrat})
  53.  
  54.  
  55.     for i in range(0,16):
  56.         print(a[i])
  57.         if(a[i]["b^2"] < 0):
  58.             print(a[i]["b^2"], factors((-1)*a[i]["b^2"]))
  59.         else:
  60.             print(a[i]["b^2"], factors(a[i]["b^2"]))
  61.        
  62. compute_table(7601)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement