def keyGeneration(self, digit): p = self.primeGeneration(digit) q = self.primeGeneration(digit) n = p * q print("p" + p.__str__()) print("q" + q.__str__()) phin = (p - 1) * (q - 1) print("phin" + phin.__str__()) e = phin - 1 print("breakpoint1") for i in range(2, phin - 1): print(i) if (fractions._gcd(i, phin) == 1): e = i break privateKey = 0 for i in range(0, phin): print(i.__str__() + "/" + phin.__str__()) if i * e % phin == 1: privateKey = i file = open('n.txt', 'w') file.write(n.__str__()) file.close() file = open('e.txt', 'w') file.write(e.__str__()) file.close() file = open('d.txt', 'w') file.write(privateKey.__str__()) file.close()
def cleverWay(): ct = time.time() for m in get_divisors(pifSum/2): for k in get_divisors(pifSum/(2*m)): if k - m < m and k - m > 0 and fractions._gcd(m,k - m) == 1: n = k - m d = pifSum/(2*m*k) print('cleverWay', (m**2+n**2)*d, 2*m*n*d, (m**2-n**2)*d, time.time() - ct)
def set_params(self, xc, yc, turtle_color, R, r, l): self.xc = xc self.yc = yc # współrzędne początkowe rysika self.turtle_color = turtle_color self.R = int(R) # promień większego okręgu self.r = int(r) # promień mniejszego self.l = l # stosunek odcinka rysik-centrum mniejszego do r # największy wspólny dzielnik promieni nwd_promienia = fractions._gcd(self.r, self.R) self.n_rot = self.r // nwd_promienia # stosunek promieni self.k = r / float(R) self.turtle.color(*turtle_color) self.alpha = 0
def maxPoints(self, A, B): hash_map = {} n = len(A) maxlen = 0 if n == 1: return 1 for i in range(n): for j in range(i + 1, n): p1 = (A[i], B[i]) p2 = (A[j], B[j]) if A[j] != A[i]: yslope = p2[1] - p1[1] xslope = p2[0] - p1[0] slope = fractions._gcd(yslope, xslope) yslope /= slope * 1.0 xslope /= slope * 1.0 else: xslope = "inf" yslope = "inf" print(xslope, yslope) print(maxlen) # print (hash_map) if (xslope, yslope) in hash_map: if i not in hash_map[(xslope, yslope)]: hash_map[(xslope, yslope)].append(i) if j not in hash_map[(xslope, yslope)]: hash_map[(xslope, yslope)].append(j) if len(hash_map[(xslope, yslope)]) > maxlen: maxlen = len(hash_map[(xslope, yslope)]) else: hash_map[(xslope, yslope)] = [] hash_map[(xslope, yslope)].append(i) hash_map[(xslope, yslope)].append(j) if len(hash_map[(xslope, yslope)]) > maxlen: maxlen = len(hash_map[(xslope, yslope)]) print(hash_map) return maxlen
def __init__(self, n1, n2): self.n1 = n1 self.n2 = n2 self.d = _gcd(self.n1, self.n2) self.dn1 = self.n1 // self.d self.dn2 = self.n2 // self.d
num of circles of "01" of len (m*n+L) with n 1's: sum (NT ((m*n+L)/d) (n/d))/((m*n+L)/d) * L/d {d\gcd(m*n+L,n)} =?= C(m*n+L, n)*L/(m*n+L) left = L/(m*n+L) sum (NT ((m*n+L)/d) (n/d)) {d\gcd(L,n)} = right ''' from Mobius import iter_Mu, iter_divisor from fractions import gcd as _gcd from sympy import binomial as C, gcd as gcds from nn_ns.math_nn import primes from sympy.abc import n gcd = lambda x, y: abs(_gcd(x, y)) def choose_without_period(n, k): r'''NT n k = sum Mu d * C(n/d, k/d) {d\gcd(n,k)} for [(n,k)!=(0,0)] NT 0 0 = 1 ''' if (n, k) == (0, 0): return 1 return sum(Mu_d * C(n // d, k // d) for Mu_d, d in iter_Mu(gcd(n, k))) NT = choose_without_period assert NT(6, 2) == 12
# 정확한 부동소수점수 계산 : decimal from decimal import Decimal price = Decimal('19.99') tax = Decimal('0.06') total = price + (price * tax) print(total) # 21.1894 penny = Decimal('0.01') print(total.quantize(penny)) # 21.19 # 유리수 계산 : fractions # 분자를 분모로 나눈 분수를 나타낼 수 있다. from fractions import Fraction print(Fraction(1, 3) * Fraction(2, 3)) # 2/9 print(Fraction(1.0 / 3.0)) # 6004799503160661/18014398509481984 print(Fraction(Decimal('1.0') / Decimal('3.0')) ) # 3333333333333333333333333333/10000000000000000000000000000 import fractions print(fractions._gcd(24, 16)) # 8 # gcd : 최소공약수
def find_smallest_multiple(n): result = 1 for i in range(1, n + 1): result = (result * i) / fractions._gcd(result, i) return result
def gcd(a, b): return _gcd(int(a), int(b))
def lcm(x, y): return (x * y) // fractions._gcd(x, y)
def phi_euler(n): amount = 0 for k in range(1, n + 1): if fractions._gcd(n, k) == 1: amount += 1 return amount
def gcd(a, b): return abs(_gcd(a, b))
import fractions print(fractions._gcd(3, 4))
def lcm(n, m): """Calculates the lowest common multiple of two numbers.""" return n * m // _gcd(n, m)
#!/usr/bin/python import numpy as np import DataPreper as dp import tensorflow as tf from fractions import _gcd from tensorflow.contrib import rnn from tensorflow.python.ops import rnn, rnn_cell train_x,train_y,test_x,test_y = dp.TrainAndTestRNN() # number of features n_featurs = train_x[0].size # data size total_size = train_y.size batch_size = _gcd(train_y.size,test_y.size) # gets the data after the split # the X data contains stock prices of 19 consecutive days # the y data is the stock price of the 20th day # reshape to a 3-dimensional tensor #train_x = train_x.reshape(train_x.shape + tuple([1])) #test_x = test_x.reshape(test_x.shape + tuple([1])) #train_y = train_y.reshape(train_y.shape + tuple([1])) #test_y = test_y.reshape(test_y.shape + tuple([1])) # rnn configuration
def main(): mult = 1 for i in range(1, 21): mult *= i // fractions._gcd(i, mult) return mult