Help me find a way to find the number of smallest numbers.
#include <iostream> using namespace std; //Сума цифр числа int allsum(int num){ int asum = 0; while(num>0){ asum += num%10; num /= 10; } return asum; } //Перевіряє в якому діапазоні число і знаходить суму цифр int check(int i){ int sum = 0; if( 0 <= i && i <= 9) sum = i; else if( 10 <= i && i <= 99) sum = i%10 + i/10; else if( 100 <= i && i <= 999) sum = allsum(i); else if( 1000 <= i && i <= 9999) sum = allsum(i); else if( 10000 <= i && i <= 99999) sum = allsum(i); else if( 100000 <= i && i <= 999999) sum = allsum(i); return sum; } int main(){ int m,n,count = 0; cin >> m >> n; for(m;m<=n;m++){ if(check(m)==1)count++; } cout << count << endl; return 0; } Minimum amount of digits
How many positive integers from the interval [M, N] have the smallest sum of digits?
Input data
In the input file there are two numbers M and N (1 ≤ M ≤ N ≤ 1000000).
Weekend danne
In the output file you need to write the answer - one number.
allsum()calls? What is the difference between the calls of this function for42and123456? - PinkTux