• Skip to primary navigation
  • Skip to content
  • Skip to primary sidebar

Pro Programming

Professional way of Programming: Learn C, C++, Java, Python, Dot Net, Android the professional way

  • Home
  • C MCQs
  • C/C++ Programs
  • Java Programs
  • C#
  • Python
  • MySQL
  • Topics
    • Arrays
    • Strings
    • Link Lists
    • Trees
    • Shapes
  • Projects
  • Articles
  • Games
You are here: Home / c programming / Find four factors of N with maximum product and sum equal to N | Set-2

Find four factors of N with maximum product and sum equal to N | Set-2

Leave a Comment


#include <bits/stdc++.h>

using namespace std;

void findfactors(int n)

{

unordered_map<int, int> mpp;

vector<int> v, v1;

for (int i = 1; i <= sqrt(n); i++) {

if (n % i == 0) {

v.push_back(i);

if (i != (n / i) && i != 1)

v.push_back(n / i);

}

}

int s = v.size();

int maxi = -1;

pair<int, int> mp1[n + 5];

for (int i = 0; i < s; i++) {

for (int j = i; j < s; j++) {

if (v[i] + v[j] < n) {

v1.push_back(v[i] + v[j]);

mp1[v[i] + v[j]] = { v[i], v[j] };

mpp[v[i] + v[j]] = 1;

}

}

}

s = v1.size();

for (int i = 0; i < s; i++) {

int el = n - (v1[i]);

if (mpp[el] == 1) {

int a = mp1[v1[i]].first;

int b = mp1[v1[i]].second;

int c = mp1[n - v1[i]].first;

int d = mp1[n - v1[i]].second;

maxi = max(a * b * c * d, maxi);

}

}

if (maxi == -1)

cout << "Not Possiblen";

else {

cout << "The maximum product is " << maxi << endl;

}

}

int main()

{

int n = 50;

findfactors(n);

return 0;

}



Source link

Filed Under: c programming Tagged With: •   Dynamic Programming, 1s and 2s, About Us, Advanced Data Structure, Advanced Topics, Advantages of BST over Hash Table, Algo ▼, Algorithm Paradigms ►, Algorithms, All Algorithms, All Data Structures, All unique triplets that sum up to a given value, Amazon, Analysis of Algorithms, Aptitude, Array, Arrays, b, Backtracking, BFS, Binary Search, Binary Search Tree, Binary Tree, Binomial Heap, Bit Algorithms, Bit Magic, Boundary Traversal of binary tree, Branch & Bound, Bubble Sort, C, c and d in an array such that a+b = c+d, C++ program for hashing with chaining, C++ Quiz, Campus Ambassador Program, Careers, check for pair in A[] with sum as x, Check if a given array contains duplicate elements within k distance from each other, Check if an array can be divided into pairs whose sum is divisible by k, Check if each internal node of a BST has exactly one child, Check whether two strings are anagram of each other, Clone a Binary Tree with Random Pointers, Company Prep, Company-wise, Competitive Programming, Compiler Design, Computer Graphics, Computer Networks, Computer Organization, Computer Organization & Architecture, Contact Us, Contests, contribute.geeksforgeeks.org, Core Subjects ►, Count distinct elements in every window of size k, Count divisible pairs in an array, Count maximum points on same line, Count number of triplets with product equal to given number, Count of index pairs with equal elements in an array, Count subarrays having total distinct elements same as original array, Count subarrays with same even and odd elements, Count subsets having distinct even numbers, Count Substrings with equal number of 0s, Courses, CPP Functions, cpp-unordered_map, CS Subjects, CS Subjects ▼, CS Subjectwise ►, Cuckoo Hashing – Worst case O(1) Lookup!, Data Structures, DBMS, Design Patterns, Detect a negative cycle., Detect Cycle in an Undirected Graph, DFS, Diagonal Traversal of Binary Tree, Dictionary, Digital Electronics, Distributing items when a person cannot take more than two items of same type, Divide and Conquer, Double Hashing, DS ▼, Elements to be added so that all elements of a range are present in array, Engg. Mathematics, Experienced Interviews, Explore More..., factor, Fibonacci Heap, Fibonacci Search, Find All Duplicate Subtrees, Find all triplets with zero sum, Find duplicates in a given array when elements are not limited to a range, Find four elements a, Find if there is a rectangle in binary matrix with corners as 1, Find Itinerary from a given list of tickets, Find number of Employees Under every Employee, Find smallest range containing elements from k lists, Find the largest subarray with 0 sum, Find three element from different three arrays such that that a + b + c = sum, Find whether an array is subset of another array, Game of replacing array elements, Game Theory, GATE ▼, GATE 2019, GATE CS Corner, GATE CS Notes, GATE Notes, GATE Official Papers, GBlog, Geek of the Month, Geek on the Top, Geeks Classes, Geometric, Geometric Algorithms, Given an array A[] and a number x, Graph, Graph Algorithms, Greedy Algorithms, Hash, Hash Table vs STL Map, Hashing, Heap, HeapSort, How to begin with Competitive Programming?, How to efficiently implement k Queues in a single array?, How to prepare for ACM-ICPC?, HTML & XML, ide.geeksforgeeks.org, Implement Queue using Stacks, Implement two stacks in an array, Implementation of Deque using circular array, Index Mapping (or Trivial Hashing), Infix to Postfix Conversion using Stack, Insertion Sort, Internal Working of HashMap in Java, Internship, Internship Interviews, Internships, Interview ▼, Interview Experiences, Introduction, Introduction to Linked List, ISRO, ISRO CS Exam, Java, Java Collections, Java-Functions, Java.lang package, Java.util Package, JavaScript, Languages, Languages ►, Languages ▼, Largest increasing subsequence of consecutive integers, Largest subarray with equal number of 0s and 1s, Largest subset whose all elements are Fibonacci numbers, Last Minute Notes, Last seen array element (last appearance is earliest), Length of longest strict bitonic subsequence, Linear Search, Linked List, Linked List Insertion, Linked List vs Array, LinkedList, Longest Consecutive Subsequence, Longest Increasing consecutive subsequence, Longest Palindromic Subsequence, Longest Path in a Directed Acyclic Graph, Longest Repeated Subsequence, Longest subarray having count of 1s one more than count of 0s, Longest subarray with sum divisible by k, Longest subsequence such that difference between adjacents is one | Set 2, Lowest Common Ancestor in a Binary Search Tree, Machine Learning, Mathematical, Mathematical Algorithms, Matrix, Maximum area rectangle by picking four sides from array, Maximum distance between two occurrences of same element in array, Maximum Product Sub-array, Merge Two Balanced Binary Search Trees, MergeSort, Microprocessor, Microsoft, Minimum delete operations to make all elements of array same, Minimum number of distinct elements after removing m items, Minimum operation to make all elements equal in array, More..., Multiple Choice Quizzes, Number Theory, Open Addressing for Collision Handling, Operating Systems, Pairs of Amicable Numbers, Palindrome Substring Queries, Pattern Searching, PHP, PHP-function, Placement Course, Practice Company Questions, Practice Problems, previous post., Print a Binary Tree in Vertical Order, Print all triplets in sorted array that form AP, Print array elements that are divisible by at-least one other, Print level order traversal line by line | Set 1, Printing longest Increasing consecutive subsequence, Privacy Policy, Program Output, Project, Puzzles, Python, Python List, QA - Placement Quizzes, Queue, Quick Sort, QuickSort, Quizzes ▼, Quizzes on BST, Randomized Algorithms, Range Queries for Frequencies of array elements, Rearrange positive and negative numbers in O(n) time and O(1) extra space, Recaman’s sequence, Recent Articles, Remove all duplicates from a given string, Return maximum occurring character in an input string, Root to leaf path with maximum distinct nodes, School Programming, Searching, Searching Algorithms, Segregate 0s and 1s in an array, Separate Chaining for Collision Handling, series, Set, Set to Array in Java, Skip to content, Software Engineering, Some rights reserved, Sorting, Sorting Algorithms, SQL, Stack, Step by Step Guide for Placement Preparation, STL, Strings, Students ▼, Subarray with no pair sum divisible by K, Subarrays with distinct elements, Subjective Questions, Sudo Placement 2, Suggest a Topic, Technical Scripter, Testimonials, The Stock Span Problem, Theory of Computation, Top 10 Algorithms and Data Structures for Competitive Programming, Top 10 algorithms in Interview Questions, Top 20 Interview Questions, Top Topics, Topic-wise, Topicwise ►, Tree, Tree based DS ►, Tuple, UGC NET CS Paper II, UGC NET CS Paper III, UGC NET Papers, UGC-NET, Union and Intersection of two linked lists, Video Tutorials, Videos, Web Technologies, Web Technology, What’s Difference?, Write an Article, Write Interview Experience

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Recent Posts

  • 5 Women Programmers Who Changed The World!
  • Wwe network subscribers reached 2.1 million
  • Surveying Questions and Answers – City and Township Surveying
  • Qualcomm Interview Experience ( On-Campus Drive)
  • 10k. Advanced WebDriver – Using Log4j Part 1
  • Privacy Policy
  • About
  • Contact US

© 2019 ProProgramming
 Privacy Policy About Contact Us