commit
b097c58a17
3 changed files with 173 additions and 0 deletions
-
97.gitignore
-
31Factorize.py
-
45f.py
@ -0,0 +1,97 @@ |
|||||
|
# ---> Python |
||||
|
# Byte-compiled / optimized / DLL files |
||||
|
__pycache__/ |
||||
|
*.py[cod] |
||||
|
*$py.class |
||||
|
|
||||
|
# C extensions |
||||
|
*.so |
||||
|
|
||||
|
# Distribution / packaging |
||||
|
.Python |
||||
|
env/ |
||||
|
build/ |
||||
|
develop-eggs/ |
||||
|
dist/ |
||||
|
downloads/ |
||||
|
eggs/ |
||||
|
.eggs/ |
||||
|
lib/ |
||||
|
lib64/ |
||||
|
parts/ |
||||
|
sdist/ |
||||
|
var/ |
||||
|
wheels/ |
||||
|
*.egg-info/ |
||||
|
.installed.cfg |
||||
|
*.egg |
||||
|
|
||||
|
# PyInstaller |
||||
|
# Usually these files are written by a python script from a template |
||||
|
# before PyInstaller builds the exe, so as to inject date/other infos into it. |
||||
|
*.manifest |
||||
|
*.spec |
||||
|
|
||||
|
# Installer logs |
||||
|
pip-log.txt |
||||
|
pip-delete-this-directory.txt |
||||
|
|
||||
|
# Unit test / coverage reports |
||||
|
htmlcov/ |
||||
|
.tox/ |
||||
|
.coverage |
||||
|
.coverage.* |
||||
|
.cache |
||||
|
nosetests.xml |
||||
|
coverage.xml |
||||
|
*,cover |
||||
|
.hypothesis/ |
||||
|
|
||||
|
# Translations |
||||
|
*.mo |
||||
|
*.pot |
||||
|
|
||||
|
# Django stuff: |
||||
|
*.log |
||||
|
local_settings.py |
||||
|
|
||||
|
# Flask stuff: |
||||
|
instance/ |
||||
|
.webassets-cache |
||||
|
|
||||
|
# Scrapy stuff: |
||||
|
.scrapy |
||||
|
|
||||
|
# Sphinx documentation |
||||
|
docs/_build/ |
||||
|
|
||||
|
# PyBuilder |
||||
|
target/ |
||||
|
|
||||
|
# Jupyter Notebook |
||||
|
.ipynb_checkpoints |
||||
|
|
||||
|
# pyenv |
||||
|
.python-version |
||||
|
|
||||
|
# celery beat schedule file |
||||
|
celerybeat-schedule |
||||
|
|
||||
|
# SageMath parsed files |
||||
|
*.sage.py |
||||
|
|
||||
|
# dotenv |
||||
|
.env |
||||
|
|
||||
|
# virtualenv |
||||
|
.venv |
||||
|
venv/ |
||||
|
ENV/ |
||||
|
|
||||
|
# Spyder project settings |
||||
|
.spyderproject |
||||
|
|
||||
|
# Rope project settings |
||||
|
.ropeproject |
||||
|
desktop.ini |
||||
|
|
||||
@ -0,0 +1,31 @@ |
|||||
|
import saveto |
||||
|
from math import log |
||||
|
from math import factorial |
||||
|
primes = tuple(saveto.load('primes')) |
||||
|
print('Made tuple') |
||||
|
def factor(c): |
||||
|
output = {} |
||||
|
if c in primes: |
||||
|
output = {c:1} |
||||
|
else: |
||||
|
n = c |
||||
|
count_0 = 0 |
||||
|
while n != 1: |
||||
|
while n%primes[count_0] != 0: |
||||
|
count_0 += 1 |
||||
|
b = primes[count_0] |
||||
|
p = round(log(n,b)) |
||||
|
while n%(b**p) != 0: |
||||
|
p -= 1 |
||||
|
n /= b**p |
||||
|
count_0 += 1 |
||||
|
if p > 0: |
||||
|
output[b] = int(p) |
||||
|
return output |
||||
|
##output = [{0:1},{1:1}] |
||||
|
##for i in range(2,30): |
||||
|
## output.append(factor(i)) |
||||
|
## if i%1000 == 0: |
||||
|
## print(i) |
||||
|
##print(output) |
||||
|
##print('{:,}'.format(primes[-1])) |
||||
@ -0,0 +1,45 @@ |
|||||
|
from math import log |
||||
|
import sys |
||||
|
sys.path.insert(0,'X:\\Users\\Raphael\\Documents\\primes\\') |
||||
|
from prime_loader import get_prime |
||||
|
p_list = [] |
||||
|
for i in range(10**3): |
||||
|
p_list += get_prime(i*10**6) |
||||
|
|
||||
|
|
||||
|
def factor(n,skip = False): |
||||
|
f = {} |
||||
|
if n in p_list and not skip: |
||||
|
f[n] = 1 |
||||
|
return f |
||||
|
for p in p_list: |
||||
|
if n%p == 0: |
||||
|
max_p = int(log(n,p)) |
||||
|
for i in range(max_p,-1,-1): |
||||
|
if n%(p**i) == 0: |
||||
|
f[p] = i |
||||
|
## print('{}**{}'.format(p,f[p])) |
||||
|
n //= p**i |
||||
|
break |
||||
|
if n == 1: |
||||
|
return f |
||||
|
def ff(n): |
||||
|
main = {} |
||||
|
for i in range(2,n+1): |
||||
|
l = factor(i) |
||||
|
for p in l.keys(): |
||||
|
try: |
||||
|
main[p] += l[p] |
||||
|
except KeyError: |
||||
|
main[p] = l[p] |
||||
|
return main |
||||
|
def prod(val,func = lambda x:x): |
||||
|
v = 1 |
||||
|
for i in val: |
||||
|
v *= func(i) |
||||
|
return v |
||||
|
def toitent(n): |
||||
|
f = factor(n) |
||||
|
c = n//prod(f.keys()) |
||||
|
return c*prod(f.keys(),lambda x: x-1) |
||||
|
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue