brocard | unsolved problem in mathematical number theory | Learning library
kandi X-RAY | brocard Summary
kandi X-RAY | brocard Summary
The code in this repository was used in an attempt to find more solutions to Brocard's problem. Up until now, only the first 1x10^12 (1 trillion) numbers have been tested in an attempt to find an additional solution. One of our primary goals was to increase the amount of values tested by three orders of magnitude.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of brocard
brocard Key Features
brocard Examples and Code Snippets
Community Discussions
Trending Discussions on brocard
QUESTION
Brocard's problem is n! + 1 = m^2
. The solutions to this problems are pairs of integers called Brown numbers (4,5)
, etc, of which only three are known.
A very literal implementation to Brocard's problem:
...ANSWER
Answered 2020-Dec-16 at 10:20Your algorithm is O(n^3)
.
You have two nested loops, and inside you use factorial()
, having O(n)
complexity itself.
Your algorithm tests all (n,m)
combinations, even those where factorial(n)
and m^2
are far apart, e.g. n=1
and m=10000
.
You always recompute the factorial(n)
deep inside the loop, although it's independent of the inner loop variable m
. So, it could be moved outside of the inner loop.
And, instead of always computing factorial(n)
from scratch, you could do that incrementally. Whenever you increment n
by 1
, you can multiply the previous factorial by n
.
A different, better approach would be not to use nested loops, but to always keep n
and m
in a number range so that factorial(n)
is close to m^2
, to avoid checking number pairs that are vastly off. We can do this by deciding which variable to increment next. If the factorial is smaller, then the next brocard pair needs a bigger n
. If the square is smaller, we need a bigger m
.
In pseudo code, that would be
QUESTION
Firstly note that u'\xc3\xa8'
is the python2 unicode string with 2 code-points, Ã
and ¨
. Next note that '\xc3\xa8'
is the python2 byte str which represents the utf8 encoding of the character è
. So u'\xc3\xa8'
and '\xc3\xa8'
, despite looking very similar are 2 very different beasts.
Now, if we try accessing https://www.sainsburys.co.uk/shop/gb/groceries/chablis/chablis-premièr-cru-brocard-75cl
in a browser all should go well.
If I define in a ipython session:
...ANSWER
Answered 2017-May-13 at 04:41The matter is that the URL on the site actually uses latin1 encoding for representing the "è" character - and for some reason, the Python 2 requests library, in its attempt to "clean-up the url automatically" before making the call, encodes the "è" character in utf-8 - that is what causes the 404 error.
Trying to encode the unicode_url in latin1 before calling requests.get does not help either - it attempts to decode that to unicode before its "clean up", and them errors on the invalid utf=8 sequence that is the code for "è" when using latin-1 (the " \xe8" char).
At this ppint is worth noting that requests with Python 3 also works with no problem at all - as the language automates text handling, requests needs less dancing back and forth the text encoding - and on my first attempt on Python 3 I just got:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install brocard
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page