Ansicht umschalten
Avatar von Pat_and_I
  • Pat_and_I

3 Beiträge seit 01.06.2021

Ist dieser Source (Python 3) zum Finden von Faktoren bereits bekannt?

#(c) by Pat_and_I 2023/2024, Ferlach, Ă–sterreich #program name: "find_any_factor" #This program finds (probably???) one factor of any nonprime number import math import decimal from datetime import datetime import sympy decimal.getcontext().prec=250 decimal.getcontext() global c #c=3 c=27071420938354717 fnd=False global pgcd pgcd=True==False #will be set to True, when you set variable "chk_one=True#==False" global chk_one chk_one=True#==False #delete the "#" between =True#==False and the program checks the numbers between a range global tstall #test all chk_square_rest() calls. also, when a gcd was fnd tstall=True==False global called_chk_square_rest called_chk_square_rest=0 global pcntcallsqurstfun pcntcallsqurstfun=True==False pcntcallsqurstfun=False start_number=0 plus_range=2 print_diff=10**10 if chk_one: pgcd=True else: tstall=False pcntcallsqurstfun=False start_number=3 #4797487931 #4378364971 #1298730659 #71710231 #5459603 #30563 plus_range=10**11 print_diff=10**8 if start_number%2==0: start_number=start_number+1 def chk_square_rest(g1): global c global fnd global pgcd global print_one_number global tstall global called_chk_square_rest if pcntcallsqurstfun==True: called_chk_square_rest=called_chk_square_rest+1 if called_chk_square_rest%1000000==0: print(called_chk_square_rest) d1=math.isqrt(g1) if d1*d1==g1 and d1>1: h1=d1 m1=math.gcd(c,h1) if m1>1 and m1<c: if pgcd: print("gcd0: ",m1," g1: ",g1) if tstall: fnd=False else: fnd=True return else: for i1 in range(0,2): d1=d1+1 e1=d1*d1-g1 if e1<0: print("........error 1: e1 is lower than null: ",e1) f1=math.isqrt(e1) if f1<1: f1=1 if f1*f1==e1: h1=d1+f1 m1=math.gcd(c,h1) if m1>1 and m1<c: if pgcd: print("gcd2: ",m1," g1: ",g1," digits(g1): ",math.trunc((math.log(g1)//math.log(10))+1)) if tstall: fnd=False else: fnd=True return else: h1=d1-f1 m1=math.gcd(c,h1) if m1>1 and m1<c: if pgcd: print("gcd1: ",m1," g1: ",g1," digits (g1): ",math.trunc((math.log(g1)//math.log(10))+1)) if tstall: fnd=False else: fnd=True return else: h1=math.gcd(c,e1) if h1>1 and h1<c: if pgcd: print("gcd: ",h1," g1: ",g1," digits (g1): ",math.trunc((math.log(g1)//math.log(10))+1)) if tstall: fnd=False else: fnd=True return def chk_it_0(): global c global fnd global pgcd global print_one_number global tstall global called_chk_square_rest chk_square_rest(c) if tstall: fnd=False if fnd: return e2=c div2=1 while e2>0: e2=e2//2 div2=div2*2 div2=div2//2 chk_square_rest(c*div2) if tstall: fnd=False if fnd: return chk_square_rest(c*div2//4*3) if tstall: fnd=False if fnd: return g2=math.isqrt(div2) if g2**2!=div2: g2=math.isqrt(div2*2) mul_save_1=g2 mul_save_2=mul_save_1//4*3 if mul_save_2<3: mul_save_2=3 if mul_save_2<mul_save_1//2: mul_save_2=mul_save_1//2 if mul_save_1>mul_save_2: j2=mul_save_1 else: j2=mul_save_2 for i2 in range(1,j2,2): chk_square_rest(c*mul_save_1*i2) if tstall: fnd=False if fnd: return chk_square_rest(c*mul_save_1*2*i2) if tstall: fnd=False if fnd: return chk_square_rest(c*mul_save_2*i2) if tstall: fnd=False if fnd: return chk_square_rest(c*mul_save_2*2*i2) if tstall: fnd=False if fnd: return called_chk_square_rest=0 date_0=datetime.now() if chk_one==True: print("number to check: ",c) pgcd=True pcntcallsqurstfun=True if not sympy.isprime(c): print("c: ",c) fnd=False if c<2: print("Number must be greater 2") else: pcntcallsqurstfun=True chk_it_0() else: print("Number: ",c,"is prime") print("count of calles for function 'chk_square_rest': ",called_chk_square_rest) print("fnd: ",fnd) else: print("Start") pgcd=False count_of_is_not_prime_checked=0 if start_number<2 or start_number%2==0: if start_number%2==0: print("Number to start must be odd") else: print("Number to start must be greater 2") print("No number was checked") else: for c in range(start_number,start_number+plus_range,2): if not sympy.isprime(c): if c%print_diff==1: print("#c: ",c) count_of_is_not_prime_checked=count_of_is_not_prime_checked+1 fnd=False chk_it_0() if not fnd: print("#c=",c," #not fnd") #print() else: if c%print_diff==1: print("#c:",c,"count_of_is_not_prime_checked: ",count_of_is_not_prime_checked) print("count of 'is not prime' checked=",count_of_is_not_prime_checked) print("calculation time: ",datetime.now()-date_0)
Bewerten
- +
Ansicht umschalten