For a given number N(0<N<100), little johnny wants to find out the minimum positive integer X divisible by N,where the sum of digits of X is equal to N,and X is not equal to N
#include <stdio.h>
long sum_digits(long n) {
long sum = 0;
while (n > 0) {
sum += n%10;
n /= 10;
}
return sum;
}
int main() {
long n, x;
scanf("%ld", &n);
x = 2*n;
while (1) {
if (sum_digits(x) == n) {
break;
}
x += n;
}
printf("%ld", x);
return 0;
}
Comments
Leave a comment