Python Forum
How do I code this equation in python (factor ceiling(2^127-1))
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I code this equation in python (factor ceiling(2^127-1))
#5
(Apr-22-2018, 07:39 AM)Pleiades Wrote: OverflowError: int too large to convert to float
You need the floating type mpmath.mpf. The following computation may be correct (read the doc!)
>>> import mpmath as mp
>>> mp.mp.dps = 1000
>>> mp.mp.prec
3325
>>> x = mp.mpf(3**1279)
>>> x
mpf('17301541007910038054176056432452867095149043770336183739760994896914962855011729112692135469308113595623662446442598795834444897233706143344824357701420610156423345105638078275879693218333055393875886226458620734496461814517152992352402982745998689203987491576943864064210130929012975963553401138869026447532834194444684876122440822192338479455455335994013248316240321358466758500551665434276274478532775337486153362645579799959393898179890245190220628605618273528084601403702463029225950540686613177600948606835157545386013111476205803857649578582946755008105822347197520438156375214337925994262260644194653867.0')
>>> x % mp.mpf('19.1')
mpf('10.19999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999986211221154848220654005392902057139770156790286166144188800371401237452170538589543598035521683264914310586337686699894347939024860146540757548385574874504630831265632890197664535441563639513497048756683543708442778829491602757769872393215591581152938167421054163471394836743703044131001404204016205461841021455948652709053963994607698563023642172696945794949806477041895118333497516253529717948650209753919929653496184540071834200082524982267781226809556415809041082332587896492941756602172886446388115227194726605314781134096334203545572724145359345153758473917409997845778716764066425820393664286016039105526')
You can do it without mpmath, using only integers:
>>> (3**1279*10) % 191
102
Reply


Messages In This Thread
RE: How do I code this equation in python (factor ceiling(2^127-1)) - by Gribouillis - Apr-22-2018, 08:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Find factor to match test curve to golden curve SriRajesh 0 1,521 Jun-17-2021, 04:39 AM
Last Post: SriRajesh
  Solve simple equation in Python kmll 4 3,024 Nov-01-2020, 04:34 PM
Last Post: deanhystad
  Python gives " -0.0 " as solution for an equation akar 2 1,739 Aug-27-2020, 12:15 PM
Last Post: akar
  Asking for help in solving a single variable nonlinear equation using Python ! NDP 0 1,965 Feb-15-2019, 12:03 PM
Last Post: NDP
  parsing text for common factor metulburr 4 4,909 Apr-28-2017, 11:04 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020