- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- 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 the largest good number in the divisors of given number N in C++

In this problem, we are given a number N. Our task is to *find the largest good number in the divisors of given number N*.

**A good number** is a number in which every digit is larger than the sum of digits of its right (all less significant bits than it). For example, 732 is a good number, 7> 3+2 and 3>2.

**Let's take an example to understand the problem,**

Input : N = 15 Output : 15

**Explanation** −

Divisors of 15 : 1, 3, 5, 15.

## Solution Approach

A simple solution to the problem is by finding all the divisors of N. And they find the largest good number which is extracted as a product of all prime divisors of the number.

## Example

Program to illustrate the working of our solution

#include <bits/stdc++.h> using namespace std; int findLargestGoodNumber(int n){ vector<int> primeFactors; int x = n; for (int i = 2; i * i <= n; i++) { if (x % i == 0) { primeFactors.push_back(i); while (x % i == 0) x /= i; } } if (x > 1) primeFactors.push_back(x); int goodNumber = 1; for (int i = 0; i < primeFactors.size(); i++) goodNumber = goodNumber * primeFactors[i]; return goodNumber; } int main(){ int n = 28; cout<<"The largest good Number in divisor of "<<n<<" is "<<findLargestGoodNumber(n); return 0; }

## Example

The largest good Number in divisor of 28 is 14

- Related Questions & Answers
- Find the number of divisors of all numbers in the range [1, n] in C++
- Count the number of common divisors of the given strings in C++
- Find the Largest number with given number of digits and sum of digits in C++
- Find sum of divisors of all the divisors of a natural number in C++
- First triangular number whose number of divisors exceeds N in C++
- Find largest sum of digits in all divisors of n in C++
- How to find the n number of largest values in an R vector?
- Find the largest palindrome number made from the product of two n digit numbers in JavaScript
- Find the largest number in a Java array.
- Find the largest number with n set and m unset bits in C++
- Find the largest number that can be formed with the given digits in C++
- Largest N digit number divisible by given three numbers in C++
- Program to find out the sum of the number of divisor of the divisors in Python
- Find number from its divisors in C++
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors in C++

Advertisements