Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6686623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:11:35+00:00 2026-05-26T05:11:35+00:00

From Python ProblemSet I would like to test the following functions but it seems

  • 0

From Python ProblemSet I would like to test the following functions but it seems that mult and coprime could not be defined. I tried importing math but that did not help. Any recommendations?

>>> import itertools
>>> def prime_factors(value):
    if value > 3:
        for this in itertools.chain(iter([2]), xrange(3,int(value ** 0.5)+1, 2)):
            if this*this > value:  break
            while not (value % this):
                if value == this: break
                value /=  this
                yield this
    yield value
>>> prime_factors(315)
generator object prime_factors at 0x01182468>
>>> def prime_factors_mult(n):
    res = list(prime_factors(n))
    return sorted([fact, res.count(fact)] for fact in set(res))
>>> prime_factors_mult(315)
[[3, 2], [5, 1], [7, 1]]
>>> def totient(n):
    from operator import mul
    if n == 1: return 1
    return reduce(mul, [(p-1) * p**(m-1) for p,m in prime_factors_mult(n)])

>>> totient(315)
144
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:11:35+00:00Added an answer on May 26, 2026 at 5:11 am

    If you check the documentation for the operator module, you’ll find that the multiplication operator is mul.

    Also, I believe the definition of coprime relies on definitions from previous problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to run a process from Python (2.4/2.5/2.6) using Popen , and
I've run into some behavior from Python 2.6.1 that I didn't expect. Here is
I have developed a python C-extension that receives data from python and compute some
I'm looking to create favicon.ico files programatically from Python, but PIL only has support
I'm using the following method to send mail from Python using SMTP. Is it
I would like to have an interface between Python and sqlite. Both are installed
I have a PyQt program used to visualize some python objects. I would like
I'd like to extract the text from an HTML file using Python. I want
I would like to do some text conversion, such as reading in from a
I would like to enable students to submit python code solutions to a few

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.