Exemplo n.º 1
0
def tester():
    my_fun = lambda x,y: divisor_count(x)*divisor_count(y)
    my_fun2 = averager(my_fun)
    print(my_fun(49,80))
    print(my_fun(50,80))
    print(my_fun(49,81))
    print(my_fun(50,81))    
    print(my_fun2(49.1,80.05))
Exemplo n.º 2
0
def factorsOfNumbers(num1):
    print("\nHere are the factors of your number: ", divisors(num1))
    print("Your number has", divisor_count(num1), "factors within it")
    if divisor_count(num1) == 2:
        print("Your number is a prime number.")
    else:
        print("Your number is a composite number.")
    print()
    print("The prime factors of your number are", primefactors(num1))
    print("A number’s prime factors are the set of prime numbers (including repeats) that equal that number when multiplied together.")
Exemplo n.º 3
0
def triangle():
    triangle = 0
    for i in itertools.count(1):
        triangle += i  # This is the ith triangle number, i.e. num = 1 + 2 + ... + i = i * (i + 1) / 2
        if divisor_count(triangle) > 500:
            print(str(triangle))
            return
Exemplo n.º 4
0
 def get(self):
     i = 1
     t = self.get_triangle(i)
     while sympy.divisor_count(t) < self.n:
         i += 1
         t = self.get_triangle(i)
     return t
Exemplo n.º 5
0
 def test_count_divisors(self):
     """Tests for count_divisors()"""
     for index in range(1, 100):
         result1 = sympy.divisor_count(index)
         result2 = p12.count_divisors(index)
         err_msg = "%d != %d for %d" % (result1, result2, index)
         self.assertEquals(result1, result2, err_msg)
Exemplo n.º 6
0
 def get(self):
     i = 1
     t = self.get_triangle(i)
     while sympy.divisor_count(t) < self.n:
         i += 1
         t = self.get_triangle(i)
     return t
Exemplo n.º 7
0
def ep12():
  dict_of_factors = {}
  for i in range(1, 1000000): # Arbitrarily large upper bound
    num = triangle_number(i)
    if divisor_count(num) > 500:
      return num
      break
Exemplo n.º 8
0
def main():
    ''' Increases size of 'tri_num' until it has over 500 divisors '''
    tri_num, natural = 1, 1
    while divisor_count(tri_num) < 500:
        natural += 1
        tri_num += natural
    print(tri_num)
Exemplo n.º 9
0
def make_tree(n):
    g = nx.DiGraph()
    for x in range(2, n + 1):
        g.add_node(x)
        y = divisor_count(x)
        g.add_edge(x, y)
    nx.draw(g, with_labels=True)
    plt.show()
Exemplo n.º 10
0
def find_x_divisors_triangle(x: int) -> int:
    triangle_number = triangle = 1
    while True:
        if (divisor_count(triangle) > x):
            return triangle

        triangle_number += 1
        triangle = get_nth_triangle(triangle_number)
Exemplo n.º 11
0
def euler12():
    num_divisors = 0
    i = 0
    while num_divisors < 500:
        i += 1
        current = triangle(i)
        num_divisors = divisor_count(current)
    print(current, num_divisors)
Exemplo n.º 12
0
def search():
    count = 0
    for v1 in range(N + 1):
        for v2 in range(N + 1):
            for n in range(max(v1, v2, 1), N + 1):
                remaining = (2**(n - v1)) * (5**(n - v2))

                a0 = 2**v1
                b0 = 5**v2
                count += sympy.divisor_count(remaining * (a0 + b0))

                if v1 == 0 or v2 == 0:
                    continue

                a0 = (2**v1) * (5**v2)
                b0 = 1
                count += sympy.divisor_count(remaining * (a0 + b0))
    return count
Exemplo n.º 13
0
def primechain(a, b):
    prime = True
    it = 0
    while (prime):
        if (divisor_count(it * it + it * a + b) == 2):
            it += 1
        else:
            prime = False
    return it
Exemplo n.º 14
0
 def num_sol(self, n):
     products = [a * b for a in self.pwrs2 for b in self.pwrs5 if a * b <= 2 * 10 ** n]
     candidates = [(a, b) for a in products for b in products if
                   a <= b and ((b + a) * 10 ** n) % (a * b) == 0 and fractions.gcd(a, b) == 1]
     listp = [((a + b) * 10 ** n) // (a * b) for a, b in candidates]
     resu = 0
     for a in listp:
         resu += sympy.divisor_count(a)
     return resu
Exemplo n.º 15
0
def ans():
    div: int = 500
    s: int = 0
    i: int = 1
    # continue until we find a number with more than 500 divisors
    while True:
        s += i
        if divisor_count(s) > div:
            return s
        i += 1
Exemplo n.º 16
0
def ahoaho():
  dmax = 0
  for n in itertools.count(1):
    c = sp.divisor_count(n**2)
    d = c//2+1
    if dmax < d:
      # print(f"n={n}\tc={c}\td={d}\t{sp.factorint(n)}")
      print(f"n={n}\tc={c}\td={d}\t{sp.factorint(n)}\t{sum(sp.factorint(n).values())}")
      dmax = d
    if dmax >= 1000:
      break
Exemplo n.º 17
0
 def num_sol(self, n):
     products = [
         a * b for a in self.pwrs2 for b in self.pwrs5 if a * b <= 2 * 10**n
     ]
     candidates = [(a, b) for a in products for b in products
                   if a <= b and ((b + a) * 10**n) %
                   (a * b) == 0 and fractions.gcd(a, b) == 1]
     listp = [((a + b) * 10**n) // (a * b) for a, b in candidates]
     resu = 0
     for a in listp:
         resu += sympy.divisor_count(a)
     return resu
Exemplo n.º 18
0
def highly_divisible_trinumber(divisors):
    """
    Returns the first triangle number with the given
    number of divisors.  Uses Sympy library to get
    the number of divisors for the triangle number.
    """
    index = 1
    while True:
        trinumber = triangle_number(index)
        if sympy.divisor_count(trinumber) > divisors:
            return trinumber
        index = index + 1
Exemplo n.º 19
0
import os

def cls():
    os.system('cls' if os.name=='nt' else 'clear')

cls()

from sympy import divisors, divisor_count

maior = 0
number = 0

for x in range(1,100):
	num = int(divisor_count(x))
	if num > maior:
		maior = num
		number = x
Exemplo n.º 20
0
#from pjeuler import gcd

# m = 1000
# v = [0]*m
# for x in range(1,m):
#   for y in range(x,m):
#     if x*y % (x+y)==0:      
#       n = x*y//(x+y)
#       v[n] += 1
#       print("1/"+str(x)+" + 1/"+str(y)+" = 1/"+str(n))

import sympy

for n in range(1,1000000):
  if sympy.divisor_count(n)<100:
    continue
  x = n+1
  a = 0
  while True:
    y = x*n/(x-n)
    if y < x:
      if a > 800:
        ndivs = sympy.divisor_count(n)
        print("For n="+str(n)+" with "+str(ndivs)+": "+str(a)+" solutions.")
      a = 0
      break
    if y==round(y):
      #print("1/"+str(x)+" + 1/"+str(round(y))+" = 1/"+str(n))
      a += 1
    x += 1
Exemplo n.º 21
0
import sympy as sp
import itertools

for n in itertools.count(1):
    c = sp.divisor_count(n**2) // 2 + 1
    if c >= 1000:
        print(n)
        break
Exemplo n.º 22
0
def primechain(a, b):
    prime = True
    it = 0
    while (prime):
        if (divisor_count(it * it + it * a + b) == 2):
            it += 1
        else:
            prime = False
    return it


biggestchain = 0
coefficients = [0, 0]
primes = []
for b in range(-1000, 1000):
    if (divisor_count(b) == 2):
        primes.append(b)

for a in range(-1000, 1000):
    for b in primes:
        c = primechain(a, b)
        if (biggestchain < c):
            biggestchain = c
            coefficients[0] = a
            coefficients[1] = b

print(coefficients[0])
print(coefficients[1])
print(coefficients[0] * coefficients[1])
Exemplo n.º 23
0
 1: 1
 3: 1,3
 6: 1,2,3,6
10: 1,2,5,10
15: 1,3,5,15
21: 1,3,7,21
28: 1,2,4,7,14,28

これから, 7番目の三角数である28は, 5個より多く約数をもつ最初の三角数であることが分かる.

では, 500個より多く約数をもつ最初の三角数はいくつか.
"""
from sympy import divisor_count
from numpy import arange


def sankaku(n):
    return sum(arange(1, n + 1))


n = 7
while True:
    b = sankaku(n)
    a = divisor_count(b)
    print a, b
    if a >= 500:
        break
    n += 1
print n, b, a
Exemplo n.º 24
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sympy
expr1 = sympy.factorint(1234567890, visual=True) # 素因数
sympy.pprint(expr1)
expr1 = sympy.divisors(1234567890) # 約数
sympy.pprint(expr1)
expr1 = sympy.divisor_count(1234567890) # 約数の個数
sympy.pprint(expr1)

Exemplo n.º 25
0
import sympy

i = 0
po = 0
while True:
    i += 1
    po += i
    if sympy.divisor_count(po) > 500:
        break

print("Answer:" + str(po))
Exemplo n.º 26
0
from functools import reduce
from sympy import divisor_count


def Sieve(n):
    sieve = [0] * (n+1)
    for d in range(2,int(n**0.5)+1):
        if sieve[d] == 0:
            s = d
            while s + d <= n:
                s += d
                sieve[s] = 1

    primes = []
    for i in range(len(sieve)):
        if sieve[i] == 0:
            primes.append(i)
    return primes[2:]

primes = Sieve(1000)

k = 0
while 3**k < 8000000:
    k += 1
print(k,3**k)

n = reduce(lambda x, y: x*y,primes[0:k])
print(n)
print((divisor_count(n**2)+1)/2)
# seems like this solution model would work but I dont know how I would go about minimising n and (tau(n**2)+1)/2 simultaneously
Exemplo n.º 27
0
"""
Created August 22, 2012

Author: Spencer Lyon
"""
from sympy import divisor_count
from time import time
start_time = time()

total = 0
its = 1
while total < 500:
    num = sum(range(its))
    total = divisor_count(num)
    its += 1


end_time = time()
elapsed_time = end_time - start_time
print "total time elapsed is ", elapsed_time, " seconds"
print num
Exemplo n.º 28
0
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
となる.

最初の7項について, その約数を列挙すると, 以下のとおり.

 1: 1
 3: 1,3
 6: 1,2,3,6
10: 1,2,5,10
15: 1,3,5,15
21: 1,3,7,21
28: 1,2,4,7,14,28

これから, 7番目の三角数である28は, 5個より多く約数をもつ最初の三角数であることが分かる.

では, 500個より多く約数をもつ最初の三角数はいくつか.
"""
from sympy import divisor_count
n=1
a=1
while True :
	b = divisor_count(a)
	print a,b
	if b>=500:
		break
	n+=1
	a+=n
print "ans=",a    

        
Exemplo n.º 29
0
import matplotlib.collections
from string import Template


def memoize(f):
    cache = {}

    def ret(a):
        if a not in cache:
            cache[a] = f(a)
        return cache[a]

    return ret


primeOmega = memoize(lambda n: divisor_count(n, 1) - 1)


def saveSpiral(filename, theta=pi * (3 - sqrt(5)), limit=2000, window=50):
    dots = array(map(lambda n: sqrt(n) * exp(1j * n * theta), range(1, limit)))

    sizes = array(
        map(lambda n: exp(-(0.7 + max(1, primeOmega(n)) / 6)), range(1,
                                                                     limit)))

    patches = [
        plt.Circle([u.real, u.imag], size) for u, size in zip(dots, sizes)
    ]

    fig, ax = plt.subplots()
    coll = matplotlib.collections.PatchCollection(patches, facecolors='black')
Exemplo n.º 30
0
#!/Library/Frameworks/Python.framework/Versions/3.7/bin/python3
from sympy import divisors, divisor_count

t=int(input())
MOD=int(1E9+7)
for i in range(t):
	n=int(input())
	if(not n):
		print(0)
		continue
	divis = int(divisor_count(n))
#	print("n {} divis_tam {}".format(n, divis))
	f=int(n**0.5) if divis&1 else 1
	r=(int(n**(divis>>1)*f))%MOD
	print(r)
Exemplo n.º 31
0
# The sequence of triangle numbers is generated by adding the natural numbers.
# So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:
# 
# 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...
# 
# Let us list the factors of the first seven triangle numbers:
# 
#      1: 1
#      3: 1,3
#      6: 1,2,3,6
#     10: 1,2,5,10
#     15: 1,3,5,15
#     21: 1,3,7,21
#     28: 1,2,4,7,14,28
# 
# We can see that 28 is the first triangle number to have over five divisors.
# 
# What is the value of the first triangle number to have over five hundred divisors?

divisors = 0
n = 1
tri = 0

while divisors < 500:
    tri = n * (n + 1) / 2
    divisors = sympy.divisor_count(tri)
    n += 1

print "The value of the first triangle number to have over five hundred divisors is", tri
Exemplo n.º 32
0
def euler12():
    for tri in polygonal_gen(3):
        if divisor_count(tri) > 500:
            return tri
Exemplo n.º 33
0
    primes = []
    for i in range(len(sieve)):
        if sieve[i] == 0:
            primes.append(i)
    return primes[2:]


def tau(n):
    primes = Sieve(n)
    exponents = []
    for p in primes:
        num = n
        temp = 0
        while num % p == 0:
            temp += 1
            num = num / p
        exponents.append(temp)

    a = 1
    for e in exponents:
        a = a * (e + 1)
    return (a)


print(tau(4294967297))
n = 1
while int((divisor_count(n**2) + 1) / 2) < 1000:
    n += 1
print(n)
Exemplo n.º 34
0
import os


def cls():
    os.system('cls' if os.name == 'nt' else 'clear')


cls()

from sympy import divisors, divisor_count

maior = 0
number = 0

for x in range(1, 100):
    num = int(divisor_count(x))
    if num > maior:
        maior = num
        number = x
Exemplo n.º 35
0
from sympy import divisors, divisor_count

N = 100
#final=0xffffffffffffffff
final=800573297242118400
inicio=int(final)-100
MOD=int(1E9+7)
for i in range(N):
	n=i+inicio
	divis = int(divisor_count(0xffffffffffffffff))
	print(n)
#	print("n {} divis_tam {}".format(n, divis))
	r=(n**(divis>>1))%MOD
#	print(r)
Exemplo n.º 36
0
def divisors(n):
    f = divisor_count(n)
    return f
Exemplo n.º 37
0
Arquivo: d.py Projeto: auk1709/atcoder
import sympy
n = int(input())

sum = 0
for i in range(1, n + 1):
    sum += i * sympy.divisor_count(i)

print(sum)
Exemplo n.º 38
0
def g(n):
  return sp.divisor_count(n**2)//2+1
Exemplo n.º 39
0
    x += 1

# %% calculate
x = 2
while True:
    if (2 + len(factors(trinum(x)))) > 400:
        print(trinum(x))
        break
    x += 1

# %% calculate
x = 2
while True:
    if (2 + len(factors(trinum(x)))) > 500:
        print(trinum(x))
        break
    x += 1

# %% fastest, easiest
import sympy as sp

num_div = 0  # number of divisors
tri_num = 0  # current triangular number
i = 0  # increment to next triangular number
while num_div <= 500:  # until we get above 500 divisors
    i += 1  # increase increment
    tri_num += i  # new triangular number
    num_div = sp.divisor_count(tri_num)

print(tri_num)  # the result
Exemplo n.º 40
0
#uses the sympy divisor_count to efficiently get divisor numbers
from sympy import divisor_count

i = 1
t = 0

thenumber = 0
count = 1
while (True):
    t += i
    if (divisor_count(t) >= 500):
        thenumber = t
        break
    i += 1

print(thenumber)
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Find the number of integers 1 < n < 107, for which n and n + 1 have the same number of positive divisors. For example, 14 has the positive divisors 1, 2, 7, 14 while 15 has 1, 3, 5, 15.
# Burada c'yi 1'den başlatmamızın nedeni ardışık asal sayılar olan 2 ve 3'ü hesaba katmaktır.

from sympy import divisor_count

c = 1
for n in range(2,10**7):
    m=divisor_count(n)
    if(m==2):
        continue
    if(m==divisor_count(n+1)):
        c += 1
print(c)