N is the smallest positive integer such that the sum of the digits of N is 18 and the sum of the digits of 2N is 27. Find N.
The smallest such N is 1449, as shown at the top of the table shown below.
ct=0;
for n=99:99999
sn=sod(n);
if sn==18
s2n=sod(2*n);
if s2n==27
disp([n 2*n])
ct=ct+1;
if ct>=25
return
end
end
end
end
where the sod function is
function sd = sod(n)
s=0;
dgts=num2str(n) ;
l=length(dgts) ;
for i=1:l
s=s+str2double(dgts(i));
end
sd=s;
end
and it lists the first 25 such
1449 2898
1494 2988
1944 3888
2349 4698
2394 4788
2439 4878
2448 4896
2484 4968
2493 4986
2844 5688
2934 5868
2943 5886
3249 6498
3294 6588
3339 6678
3348 6696
3384 6768
3393 6786
3429 6858
3438 6876
3447 6894
3474 6948
3483 6966
3492 6984
3744 7488
|
Posted by Charlie
on 2024-01-16 08:41:18 |