- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find minimum number to be divided to make a number a perfect square in C++
Suppose we have a number N. We have to find minimum number that divide N to make it perfect square. So if N = 50, then minimum number is 2, as 50 / 2 = 25, and 25 is a perfect square.
A number is perfect square if it has even number of different factors. So we will try to find the prime factors of N, and find each prime factor power. Find and multiply all prime factors whose power is odd.
Example
#include<iostream> #include<cmath> using namespace std; int findMinimumNumberToDivide(int n) { int prime_factor_count = 0, min_divisor = 1; while (n%2 == 0) { prime_factor_count++; n /= 2; } if (prime_factor_count %2) min_divisor *= 2; for (int i = 3; i <= sqrt(n); i += 2) { prime_factor_count = 0; while (n%i == 0) { prime_factor_count++; n /= i; } if (prime_factor_count%2) min_divisor *= i; } if (n > 2) min_divisor *= n; return min_divisor; } int main() { int n = 108; cout << "Minimum number to divide is: " << findMinimumNumberToDivide(n) << endl; }
Output
Minimum number to divide is: 3
- Related Articles
- Find the least number by which 45 must be divided to make it a perfect square.
- Find the smallest number by which 7776 is to be divided to get a perfect square.
- Find the smallest number by which 396 must be divided to obtain a perfect square. Also find the square root of the perfect square so obtained.
- Find the smallest number by which 5103 can be divided to get a perfect square. Also find the square root of the perfect square so obtained.
- What least number must be added to 81180 to make it a perfect square?
- Find the smallest number by which 10,368 should be multiplied to make it a perfect square.
- Find the least number by which 8 must be multiplied to make it a perfect square.
- Find the smallest number by which the given number must be divided so that it becomes a perfect square: $3200$.
- Find the smallest number by which 85176 must be divided so that it becomes a perfect square
- Find the smallest number by which 1152 must be divided so that it becomes a perfect square. Also find the number whose square is the resulting number.
- Which is the smallest number by which 725 must be divided to make it a perfect cube?
- Find the smallest number by which 28812 must be divided so that the quotient becomes a perfect square.
- Find the smallest number by which 3645 must be divided so that it becomes a perfect square. Also, find the square root of the resulting number.
- Find the smallest number by which 1152 must be divided so that it becomes a perfect square. Also, find the square root of the number so obtained.
- By which smallest number should we multiply the number 3179 to make it a perfect square?

Advertisements