Question

You are given a positive integer n, break it into the sum of at least two...

You are given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum 2 product you can get. (Example Input: 10, Output: 36, Explanation: 10 = 3 3 4 = 36). What is your answer for n = 82.

Write a python code for this

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import math
# function claculating maximizeProduct
def maximize_Product(num):
   # if num is 2 then 1+1=2 ,result 1*1 =1
   if(num==2):
       return 1;
   # if num is 3 then 2+1=3 ,result 2*1 =2
   if(num==3):
       return 2;
   #if any other number except 1 or 2 or 3
   mProd=0;
   # for breaking in to 3 numbers we using mod 3
   if(num % 3==0):
       mProd = pow(3, int(num/3));
       return mProd;
   elif(num%3==1):
       mProd = 2 * 2 * pow(3, int(num/3) - 1)
       return mProd;
   elif(num%3==2):
       mProd = 2 * pow(3, int(num/3))
       return mProd;
#main program
num=int(input())   
mProduct = maximize_Product(num)
print("product : ", mProduct)

Add a comment
Know the answer?
Add Answer to:
You are given a positive integer n, break it into the sum of at least two...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java problem In this problem, the first input is a positive integer called n that will...

    Java problem In this problem, the first input is a positive integer called n that will represent the number of lines to process. The lines to be processed have one or more integers separated by whitespaces. For each of these lines, you must output: The minimum value of the integers The maximum value of the integers The sum of the integers It is worth to mention that the number of integers of each line is not known a priori and...

  • DEFINITION: For a positive integer n, τ(n) is the number of positive divisors of n and...

    DEFINITION: For a positive integer n, τ(n) is the number of positive divisors of n and σ(n) is the sum of those divisors. 4. The goal of this problem is to prove the inequality in part (b), that o(1)+(2)+...+on) < nº for each positive integer n. The first part is a stepping-stone for that. (a) (10 points.) Fix positive integers n and k with 1 <ksn. (i) For which integers i with 1 <i<n is k a term in the...

  • Write a C++ program to read an unknown number of integer values and find the sum...

    Write a C++ program to read an unknown number of integer values and find the sum of only negative integers. Use variable n to store the user input. Hint: Check Example6E.cpp (Lecture 6) Note: Use the "Check" button to verify your answer. You can modify your code and check until you get it right. For example: Test Input Result -11 A list of integers -10 12 1 14 -1

  • Challenge activity: A partition of a positive integer n is the expression of n as the sum of positive integers, whe...

    Challenge activity: A partition of a positive integer n is the expression of n as the sum of positive integers, where order does not matter. For example, two partitions of 7 are 7 1+1+1+4 and 7=1+1+1+2+2. A partition of n is perfect if every integer from 1 to n can be written uniquely as the sum of elements in the partition. 1+1+1+4 is perfect since 1-7 are expressed only as 1, 1+1, 1+1+1, 4, 1+4, 1+1+4 and 1+1+1+4, but 1+1+1+2+2...

  • IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns...

    IN PYTHON: Write a function that takes, as an argument, a positive integer n, and returns a LIST consisting of all of the digits of n (as integers) in the same order. Name this function intToList(n). For example, intToList(123) should return the list [1,2,3].

  • Write a Java Program to find the sum of all factors of a given positive integer....

    Write a Java Program to find the sum of all factors of a given positive integer. Make sure to satisfy and show different results for any inputs, for example, 0, negative numbers, odd numbers, prime numbers, huge integers, etc. For example, if the integer is 12: Then the factors are: 1, 2, 3, 4, 6, 12 ; And their sum is: 28.

  • Write a Python function binom_product that takes integer arguments a and b and positive integer argument...

    Write a Python function binom_product that takes integer arguments a and b and positive integer argument n and returns the product of the coefficients in the expansion of (ax + by)”. Example: Let a = 2, b = -1, and n = 3. Then (2x – y)3 = 8x3 – 12x²y + 6xy2 – 43 The product of the expansion coefficients is 8 x -12 x 6 x -1 = 576 Notes: There are two visible test cases and three...

  • Write a function findEvens that takes an integer, n, as input and returns the list of...

    Write a function findEvens that takes an integer, n, as input and returns the list of even integers between 1 and n. Ex. Input: 10 Output: [2,4,6,8,10] Write a function sortList that takes in a list of strings and returns a list of those strings now sorted and lowercase. Ex. Input: [‘ABE’,’CAD’,’gaB’] Output: [‘abe’,’acd’,’abg’] Both done in Python

  • Prime numbers are the building blocks of all integers greater than 1. Any integer n >...

    Prime numbers are the building blocks of all integers greater than 1. Any integer n > 1 can be written as a unique product of primes i.e. n = p1 × p2 × ... × pm. Here, pi are primes such that p1 ≤ p2 ≤ ... ≤ pm. Take, for example, the number 18. It can be written as 18 = 2 × 3 × 3. 1. Write a Python function prime divisors(n) which accept an integer n and...

  • Q(1) Given a rope of length n meters, cut the rope in different parts of integer...

    Q(1) Given a rope of length n meters, cut the rope in different parts of integer lengths in a way that maximizes product of lengths of all parts. You must make at least one cut. Assume that the length of rope is more than 2 meters Examples: (n-4) Input: rope length is 4 Output: 2*2-4(Maximum obtainable product is 2*2) Input: rope length is 5 Output: 2*3-6 (Maximum obtainable product is 2*3) (n-5) Input: rope length is 10 (n- 10) Output:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT