Represent N as a sum of the fewest numbers of the form d000

Updated

Given a number N, the task is to represent N as sum of minimum numbers of the form d000……, i.e, numbers having all digits as 0 except the first digit.

Examples :

Input : N = 1009
Output : 1000 9

Input : N = 9876
Output : 9000 800 70 6

Input : N = 10
Output : 10

Approach :

Extract digit of N one by one and multiply it by it’s position from left and store in a vector. At last print the vector.

Let the number be 9876
Extact digit of 9876 one by one
6 - > 6*1 = 6
7 - > 7*10 = 70
8 - > 8*100 = 800
9 - > 9*1000 = 9000
So 9876 = 9000 + 70 + 800 + 6

Implementation :

// C++ implementation to represent N as 
// sum of minimum numbers of the form d000......
#include <bits/stdc++.h>
using namespace std;

#define ll long long int

// Function to represent N as 
// sum of minimum numbers of the form d000......
void findTerms(ll n)
{
    // vector to store terms to represent N
    vector<int> terms;
    int power = 1;
    while (n > 0) 
    {
        int digit = n % 10;
        if ( digit > 0) 
        {
            terms.push_back(digit * power);
        }
        n /= 10;
        power *= 10;
    }
    
    for (int i = 0; i < terms.size(); i++)
    cout << terms[i] << " ";
}

// Driver Code
int main()
{
    ll n = 9876;    
    findTerms(n);
    return 0;
}

Output :

6 70 800 9000
Comment
Next tutorial
Mithlesh Upadhyay Published 21 Nov 2026 · 1 min read

Mithlesh Upadhyay is a Computer Science and AI expert from Madhya Pradesh with strong academic background (BE in CSE and M.Tech in AI) and over six years of experience in technical content development. He has contributed tech articles, led teams, and worked in Full Stack Development and Data Science. He founded the w3colleges.org portal for learning resources.

Related tutorials