Update all new Tasks
This commit is contained in:
parent
00a190b0a6
commit
91df62d461
5697 changed files with 93386 additions and 804 deletions
20
Task/AKS-test-for-primes/Python/aks-test-for-primes-1.py
Normal file
20
Task/AKS-test-for-primes/Python/aks-test-for-primes-1.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
def expand_x_1(p):
|
||||
ex = [1]
|
||||
for i in range(p):
|
||||
ex.append(ex[-1] * -(p-i) / (i+1))
|
||||
return ex[::-1]
|
||||
|
||||
def aks_test(p):
|
||||
if p < 2: return False
|
||||
ex = expand_x_1(p)
|
||||
ex[0] += 1
|
||||
return not any(mult % p for mult in ex[0:-1])
|
||||
|
||||
|
||||
print('# p: (x-1)^p for small p')
|
||||
for p in range(12):
|
||||
print('%3i: %s' % (p, ' '.join('%+i%s' % (e, ('x^%i' % n) if n else '')
|
||||
for n,e in enumerate(expand_x_1(p)))))
|
||||
|
||||
print('\n# small primes using the aks test')
|
||||
print([p for p in range(101) if aks_test(p)])
|
||||
15
Task/AKS-test-for-primes/Python/aks-test-for-primes-2.py
Normal file
15
Task/AKS-test-for-primes/Python/aks-test-for-primes-2.py
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
print('''
|
||||
{| class="wikitable" style="text-align:left;"
|
||||
|+ Polynomial Expansions and AKS prime test
|
||||
|-
|
||||
! <math>p</math>
|
||||
! <math>(x-1)^p</math>
|
||||
|-''')
|
||||
for p in range(12):
|
||||
print('! <math>%i</math>\n| <math>%s</math>\n| %r\n|-'
|
||||
% (p,
|
||||
' '.join('%s%s' % (('%+i' % e) if (e != 1 or not p or (p and not n) ) else '+',
|
||||
(('x^{%i}' % n) if n > 1 else 'x') if n else '')
|
||||
for n,e in enumerate(expand_x_1(p))),
|
||||
aks_test(p)))
|
||||
print('|}')
|
||||
Loading…
Add table
Add a link
Reference in a new issue