Find the minimum number to be divided to make the number as a perfect squareInput Format:Accept an Integer value as inputOutput Format:Print the minimum number to be dividedConstraints:0<=input<=10^15Sample Input 1:100Sample Output 1:1Sample Input 2:24Sample Output 2:6
Question
Find the minimum number to be divided to make the number as a perfect squareInput Format:Accept an Integer value as inputOutput Format:Print the minimum number to be dividedConstraints:0<=input<=10^15Sample Input 1:100Sample Output 1:1Sample Input 2:24Sample Output 2:6
Solution
To find the minimum number to be divided in order to make a given number a perfect square, we can follow these steps:
- Accept an integer value as input.
- Check if the input number is already a perfect square. If it is, then the minimum number to be divided is 1. Print 1 as the output and end the program.
- If the input number is not a perfect square, we need to find the minimum number to be divided.
- Start a loop from 2 and increment the loop variable until the square of the loop variable is greater than or equal to the input number.
- Inside the loop, check if the square of the loop variable is equal to the input number. If it is, then the minimum number to be divided is the loop variable. Print the loop variable as the output and end the program.
- If the loop completes without finding a perfect square, we need to find the factors of the input number.
- Start a loop from 2 and increment the loop variable until the loop variable is less than or equal to the square root of the input number.
- Inside the loop, check if the input number is divisible by the loop variable. If it is, then the minimum number to be divided is the loop variable. Print the loop variable as the output and end the program.
- If the loop completes without finding a factor, the minimum number to be divided is the input number itself. Print the input number as the output and end the program.
Here is the code in Python:
import math
# Step 1: Accept an integer value as input
input_number = int(input("Enter a number: "))
# Step 2: Check if the input number is already a perfect square
if math.isqrt(input_number) ** 2 == input_number:
print("1")
exit()
# Step 4: Find the minimum number to be divided
for i in range(2, input_number):
if i ** 2 >= input_number:
# Step 5: Check if the square of the loop variable is equal to the input number
if i ** 2 == input_number:
print(i)
exit()
break
# Step 7: Find the factors of the input number
for i in range(2, math.isqrt(input_number) + 1):
if input_number % i == 0:
print(i)
exit()
# Step 9: If no factor is found, the minimum number to be divided is the input number itself
print(input_number)
Sample Input 1: 100 Sample Output 1: 1
Sample Input 2: 24 Sample Output 2: 6
Similar Questions
Given 2 numbers, find the minimum of these 2 numbersInput Format:Accept two integer values as inputs.Output Format:Print the output as "Minimum of INPUT1 and INPUT2 is ____".Constraints:-10^15 <= INPUT <= 10^15Sample Input 1:10 20Sample Output 1:Minimum of 10 and 20 is 10Sample Input 2:10 200Sample Output 2:Minimum of 10 and 200 is 10
Problem Statement:Given a number, check whether it is a perfect square or not.Input Format:Given an integer n.Output Format:Print Yes if it is a perfect square or No if it is not.Constraints1 <= n <= 10^6Sample Input 1:100Sample Output 1:YesSample Input 2:34Sample Output 2:No
Multiply the given two numbers without using * operator.Input Format:Accept two integers as input.Output Format:Print the output as product of input1 and input2Constraints:1 <= INPUT <= 10^15Sample Input :10 2Sample Output :20
5*************************6************************************Input Format:Accept an integer as inputOutput Format:Print the square pattern, similar to sample input.Constraints:1<=N<100Sample Input 1:5Sample Output 1:*************************Sample Input 2:7Sample Output 2:*************************************************
Problem Statement:Accept two integers and print quotient with 16 decimal places and print the remainder in next line.Input Format:Accept two integers as inputOutput Format:Print Quotient and Remainder as follows:The quotient when NUM1 is divided by NUM2 is QUOTIENT_VALThe remainder when NUM1 is divided by NUM2 is REM_VALConstraints:1<=N1,N2<=10^15Sample Input 1:54 65Sample Output 1:The quotient when 54 is divided by 65 is 0.8307692307692308The remainder when 54 is divided by 65 is 54Sample Input 2:23 78Sample Output 2:The quotient when 23 is divided by 78 is 0.2948717948717949The remainder when 23 is divided by 78 is 23
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.