Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C
  • C Basics
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Arrays
  • C Strings
  • C Pointers
  • C Preprocessors
  • C File Handling
  • C Programs
  • C Cheatsheet
  • C Interview Questions
  • C MCQ
  • C++
Open In App
Next Article:
C++ Program To Find All Factors of A Natural Number
Next article icon

C Program to Find minimum sum of factors of number

Last Updated : 20 Oct, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Write a C program for a given number N, the task is to find the minimum sum of its factors.

Examples:

Input : 12
Output : 7
Explanation:

Following are different ways to factorize 12 and
sum of factors in different ways.
12 = 12 * 1 = 12 + 1 = 13
12 = 2 * 6 = 2 + 6 = 8
12 = 3 * 4 = 3 + 4 = 7
12 = 2 * 2 * 3 = 2 + 2 + 3 = 7
Therefore minimum sum is 7

Input: 105
Output: 15

Approach:

To minimize sum, we must factorize factors as long as possible. With this process, we prime factors. So to find minimum sum of product of number, we find sum of prime factors of product.

Below is the implementation of the above approach:

C




// C program for the above approach
#include <stdio.h>
 
// To find the minimum sum of the product of numbers
int findMinSum(int num)
{
    int sum = 0;
 
    // Find factors of the number and add to the sum
    for (int i = 2; i * i <= num; i++) {
        while (num % i == 0) {
            sum += i;
            num /= i;
        }
    }
    sum += num;
 
    // Return the sum of numbers having the minimum product
    return sum;
}
 
// Drivers Code
int main()
{
    int num = 12;
 
    printf("%d\n", findMinSum(num));
 
    return 0;
}
 
 
Output
7 

Time Complexity : O(n1/2 * log n)
Auxiliary Space: O(1)

Please refer complete article on

Find minimum sum of factors of number

for more details!



Next Article
C++ Program To Find All Factors of A Natural Number
author
kartik
Improve
Article Tags :
  • C Programs

Similar Reads

  • C Program for Find sum of odd factors of a number
    Write a C program for a given number n, the task is to find the odd factor sum. Examples: Input : n = 30Output : 24Explanation: Odd dividers sum 1 + 3 + 5 + 15 = 24 Input : 18Output : 13Explanation: Odd dividers sum 1 + 3 + 9 = 13 C Program for Find sum of odd factors of a number using Prime Factori
    3 min read
  • C Program to Find All Factors of Number
    In this article, we will learn to write a C program to print all distinct divisors of a number n. Factors of a number are the positive integers that divide the number without leaving a remainder. For example, for n = 10, the factors will be 1, 2, 5 and 10. Note: This problem is different from findin
    2 min read
  • C++ Program to find sum of even factors of a number
    Given a number n, the task is to find the even factor sum of a number. Examples: Input : 30 Output : 48 Even dividers sum 2 + 6 + 10 + 30 = 48 Input : 18 Output : 26 Even dividers sum 2 + 6 + 18 = 26 Let p1, p2, … pk be prime factors of n. Let a1, a2, .. ak be highest powers of p1, p2, .. pk respect
    3 min read
  • C++ Program To Find All Factors of A Natural Number
    Given a natural number n, print all distinct divisors of it. Examples: Input : n = 10 Output: 1 2 5 10 Input: n = 100 Output: 1 2 4 5 10 20 25 50 100 Input: n = 125 Output: 1 5 25 125 Note that this problem is different from finding all prime factors. Recommended PracticeCount Numbers in RangeTry It
    3 min read
  • Maximize the product of four factors of a Number
    Given an integer N, the task is to find the maximum product of A, B, C, D such that below conditions satisfy: N%A ==0 && N%B ==0 && N%C ==0 && N%D ==0.Maximize the product A*B*C*D where N = A+B+C+D. If no solution exists, print '-1' (without quotes). Examples: Input: N = 8 Ou
    15+ min read
  • Minimum number of given operation required to convert n to m
    Given two integers n and m, in a single operation n can be multiplied by either 2 or 3. The task is to convert n to m with a minimum number of given operations. If it is impossible to convert n to m with the given operation then print -1.Examples: Input: n = 120, m = 51840 Output: 7 120 * 2 * 2 * 2
    5 min read
  • Sum of M maximum distinct digit sum from 1 to N that are factors of K
    Given an array of natural numbers upto N and two numbers M and K, the task is to find the sum of M maximum distinct digit sum M numbers from N natural numbers which are factors of K. Examples: Input: N = 50, M = 4, K = 30 Output: 16 Explanation: From 1 to 50, factors of 30 = {1, 2, 3, 5, 6, 10, 15,
    11 min read
  • Find number of factors of N when location of its two factors whose product is N is given
    Given a and b which represent the location of two factors of N whose product is equal to the number N when the factors are arranged in ascending order. The task is to find the total number of factors of N.Examples: Input : a = 2, b = 3 Output : 4 N = 6 factors are {1, 2, 3, 6} No of factors are 4 In
    4 min read
  • Minimum count of numbers required with unit digit X that sums up to N
    Given two integers N and X, the task is to find the minimum count of integers with sum N and having unit digit X. If no such representation exists then print -1.Examples: Input: N = 38, X = 9 Output: 2 Explanation: Minimum two integers are required with unit digit as X to represent as a sum equal to
    7 min read
  • C++ Program for Minimum product pair an array of positive Integers
    Given an array of positive integers. We are required to write a program to print the minimum product of any two numbers of the given array.Examples: Input : 11 8 5 7 5 100 Output : 25 Explanation : The minimum product of any two numbers will be 5 * 5 = 25. Input : 198 76 544 123 154 675 Output : 744
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences