Skip to content

Conversation

@fpringle
Copy link
Contributor

Name: Semidivisible numbers

For an integer n ≥ 4, we define the lower prime square root of n, denoted by lps(n), as the largest prime ≤ √n and the upper prime square root of n, ups(n), as the smallest prime ≥ √n.

So, for example, lps(4) = 2 = ups(4), lps(1000) = 31, ups(1000) = 37.
Let us call an integer n ≥ 4 semidivisible, if one of lps(n) and ups(n) divides n, but not both.

The sum of the semidivisible numbers not exceeding 15 is 30, the numbers are 8, 10 and 12.
15 is not semidivisible because it is a multiple of both lps(15) = 3 and ups(15) = 5.
As a further example, the sum of the 92 semidivisible numbers up to 1000 is 34825.

What is the sum of all semidivisible numbers not exceeding 999966663333 ?

Note:

My solution is very similar at its core to sol1.py. Mine removes a few loops that slow down the algorithm and adds a nice prime iterator.

Reference: https://projecteuler.net/problem=234
Reference: #2695

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Announcement:

@fpringle

This message is sent to all pull requests which are OPEN, NOT MERGED, not containing 'wontfix' label and contains 'Project Euler' or 'Project' or 'Euler' (case doesn't matter) in their title. If this message doesn't apply to your pull request, please ignore this.

Message:

This is to notify all the users submitting a pull request for the Project Euler solution that the README.md file has been updated with all the style requirements necessary for the directory and solution files. Please read through it and make all the necessary changes required to your submission.

return itertools.compress(itertools.count(), primes)


def pairwise(iterable: Iterator[int]) -> Iterator[tuple]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def pairwise(iterable: Iterator[int]) -> Iterator[tuple]:
def pairwise(iterable: Iterator[int]) -> Iterator[tuple[int]]:

Is that correct?
Also, do you want an Iterator or an Iterable as your input?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutey right, thanks!

@dhruvmanila
Copy link
Member

Please leave a newline between the docstring and doctest

@dhruvmanila dhruvmanila added the awaiting changes A maintainer has requested changes to this PR label Oct 16, 2020
@github-actions
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Used to mark an issue or pull request stale. label Nov 15, 2020
@stale
Copy link

stale bot commented Nov 22, 2020

Please reopen this pull request once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to seek help from our Gitter or ping one of the reviewers. Thank you for your contributions!

@stale stale bot closed this Nov 22, 2020
@fpringle fpringle deleted the problem_234 branch December 7, 2020 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting changes A maintainer has requested changes to this PR stale Used to mark an issue or pull request stale.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants