コード例 #1
0
ファイル: test_ntheory.py プロジェクト: hitej/meta-core
def test_partitions():
    assert [npartitions(k) for k in range(13)] == [1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, 56, 77]
    assert npartitions(100) == 190569292
    assert npartitions(200) == 3972999029388
    assert npartitions(1000) == 24061467864032622473692149727991
    assert npartitions(2000) == 4720819175619413888601432406799959512200344166
    assert npartitions(10000) % 10 ** 10 == 6916435144
    assert npartitions(100000) % 10 ** 10 == 9421098519
コード例 #2
0
ファイル: test_ntheory.py プロジェクト: pducks32/intergrala
def test_partitions():
    assert [npartitions(k) for k in range(13)] == \
        [1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, 56, 77]
    assert npartitions(100) == 190569292
    assert npartitions(200) == 3972999029388
    assert npartitions(1000) == 24061467864032622473692149727991
    assert npartitions(2000) == 4720819175619413888601432406799959512200344166
    assert npartitions(10000) % 10**10 == 6916435144
    assert npartitions(100000) % 10**10 == 9421098519
コード例 #3
0
ファイル: problem078.py プロジェクト: dulaccc/project_euler
def fast_but_wrong():
  """
  http://mathworld.wolfram.com/PartitionFunctionPCongruences.html

  and divisble by 10**6 = 2**6 * 5**6  (prime factorisation)

  Watson (1938) then proved the general congruence
  P(n) congru 0 (mod 5^a) if 24*n congru 1 (mod 5^a)

  cad   
  24*n = b*5**6 + 1 = b*(15625) + 1
  so we can deduce n

  n = k*5**6 - 651 for k >= 1

  and we want P(n) = b'*1 000 000
  so P(k*5**6 - 651) = b'*1 000 000
  """
  plist = [1,1,2,3,5]
  def euler_p(n):
    if n >= len(plist):
      pn = 0
      for k in range(1,n+1):
        k1 = int(n - 1./2*k*(3*k-1))
        k2 = int(n - 1./2*k*(3*k+1))
        if k1 >= 0:
          pn += ((-1)**(k+1))*(euler_p(k1))
        if k2 >= 0:
          pn += ((-1)**(k+1))*(euler_p(k2))
      plist.append(pn)
    return plist[n]

  from sympy.ntheory import npartitions
  k = 1
  while True:
    n = k*5**6 - 651
    #n = k

    # # p(7*k + 5) congru 0 (mod 7)
    # if (n-5)%7==0:
    #   print "p(%d) divisible par 7" % n
    # # p(11*k + 6) congru 0 (mod 11)
    # elif (n-6)%11==0:
    #   print "p(%d) divisible par 11" % n
    # # p(11**3 * 13 * k + 237) congru 0 (mod 13)
    # elif (n-237)%(13*11**3)==0:
    #   print "p(%d) divisible par 13" % n
    # else:
    p = npartitions(n)

    # show that there is often a error of 1 in the npartitions result
    # if p != euler_p(n):
    #   print "NANNNN", p, euler_p(n)
    #   raw_input()

    if (p-1)%N==0 or p%N==0 or (p+1)%N==0:
      print "Potential", n, p
      print " compute euler value"
      print "", euler_p(n)
      raw_input("continue ?")
    else:
      print "OUT", n, str(p)[-10:]
    k += 1
  return n,p
コード例 #4
0
ファイル: 76.py プロジェクト: americanjetset/project_euler
from sympy.ntheory import npartitions

print(npartitions(100) - 1)
コード例 #5
0
from sympy.ntheory import npartitions
import sys

for n in range(0, sys.maxsize**10):
    np = npartitions(n)
    if np % 1000000 == 0:
        print(n)
        print(np)
    if n % 10000 == 0:
        print(n)
        print(np)
コード例 #6
0
# Let p(n) represent the number of different ways in which n coins can be separated into piles.
# For example, five coins can be separated into piles in exactly seven different ways, so p(5)=7.
# OOOOO
# OOOO   O
# OOO   OO
# OOO   O   O
# OO   OO   O
# OO   O   O   O
# O   O   O   O   O
# Find the least value of n for which p(n) is divisible by one million.

from sympy.ntheory import npartitions

for i in range(1, 100000):
    x = npartitions(i)
    if x % 1000000 == 0:
        print('resultaat: ', x)
        print('n: ', i)
        break
    if i % 1000 == 0:
        print('tussenstand: ', i, x)