Find the smallest positive integer which ends in n, is divisible by n and whose digits sum to n

33

6

It's all in the title...

Take as input a positive integer n>=12 and... do what the title says.

Yes, this is on OEIS A187924.

Some test cases

12 -> 912  
13 -> 11713  
14 -> 6314  
15 -> 915  
16 -> 3616  
17 -> 15317  
18 -> 918  
19 -> 17119 
20 -> 9920  
40 -> 1999840   
100-> 99999999999100

This is . Shortest code in bytes wins!

user72269

Posted 2017-11-27T09:43:54.207

Reputation:

Comments are not for extended discussion; this conversation has been moved to chat.

– Martin Ender – 2017-12-09T14:12:08.713

To close up a part of what was moved to chat: my edit to the OEIS proving that 11 is the only number without a solution was just approved. – Ørjan Johansen – 2018-01-21T04:55:59.860

Answers

19

Befunge, 81 bytes

&>00p0v<!%g0<
v%"d":_>1+:0^
>00g->#^_:0v
0g10g-#^_.@1>
>0p:55+/\:v>
^1+g01%+55_$^

Try it online!

Can handle up to n = 70 at least, after which some values will start overflowing the stack cell size on most implementations, and on those that don't, it'll take so long that it's not worth waiting to find out.

Given those constraints, we don't even bother trying to handle values of n greater than 99, which means we can more easily test if the value ends in n with by simply comparing the value modulo 100 with n.

Below is more detailed breakdown of the code.

Source code with execution paths highlighted

* Read n from stdin and save in memory.
* Initialize the test value v to 0 and start the main loop, incrementing v up front.
* Test if v%n == 0, and if not return to the start of the main loop.
* Test if v%100 == n, and if not return to the start of the main loop.
* Sum the digits in v by repeatedly adding v modulo 10 and dividing v by 10.
* Test if the sum is equal to n, and if not return to the start of the main loop.
* Otherwise output v and exit.

James Holderness

Posted 2017-11-27T09:43:54.207

Reputation: 8 298

13

JavaScript (ES6), 55 54 bytes

f=(s,p=0,a=p+s)=>a%s|eval([...a].join`+`)-s?f(s,p+1):a
<input type=number min=12 oninput=o.textContent=f(this.value)><pre id=o>

Takes input as a string. Needs a browser with tail recursion support for the larger results. Edit: Saved 1 byte thanks to @Arnauld.

Neil

Posted 2017-11-27T09:43:54.207

Reputation: 95 035

eval([s,...a].join`-`)? would also work, though it's not any shorter... – ETHproductions – 2017-11-27T14:57:07.527

@Arnauld No, I just forgot that I can do that with ||. – Neil – 2017-11-27T15:26:58.990

12

05AB1E, 14 bytes

[NI«ÐIÖsSOIQ*#

Try it online!

Explanation

Solutions requiring large prefixes will time out on TIO

[                # start a loop
 NI«             # append input to current iteration number
    Ð            # triplicate
     IÖ          # is the first copy evenly divisible by input?
       sSOIQ     # is the digit sum of the second copy equal to the input?
            *    # multiply
             #   # if true, break loop
                 # output the third copy

Emigna

Posted 2017-11-27T09:43:54.207

Reputation: 50 798

If feel as if 05AB1E is cheating, because it's so good. The only way to beat this by a mile would be to make a programming 'compression' language that references past language. I submit ans = dic[1] lol – Pathfinder – 2017-11-27T14:40:52.003

@Pathfinder: There are a couple of languages out there that can consistently beat 05AB1E, so we can still hope to see something even shorter :) – Emigna – 2017-11-27T15:04:51.497

8

Brachylog v2, 12 10 bytes

a₁.;A×?≜ẹ+

Try it online!

This is a function submission that takes input via . and produces output via ? (the opposite of the normal convention; all Brachylog functions have exactly two arguments, which can be input or output arguments, but the language doesn't enforce any particular argument usage). We don't normally consider conventions for argument usage to be relevant at PPCG.

Explanation

A previous version of this solution had a special case (Ḋ|, i.e. "return digits literally") for single digits, but the question apparently states that you don't have to check for that (thanks @DLosc for catching this), so I removed it. (The solution as written won't work on single digits as Brachylog won't consider 1 as a possibility for an unknown in a multiplication, to prevent infinite loops; its multiplications are arbitrary-arity.)

So this answer now goes for a pretty much direct translation of the specification. Starting with ? (the output / number we're trying to find; a Brachylog predicate always implicitly starts with ?) we use a₁. to assert that it has . (the input) as a suffix. Then ;A×? means that we can multiply (×) the result by something (;A) to produce ? (the output). Finally, ẹ+ sums (+) the digits () of ?, and there's by default an implicit assertion at the end of every Brachylog program that the final result produces .. So in other words, this program is ". is a suffix of ?, . multiplied by something is ?, . is the digit sum of ?", which is very close to a literal translation of the original program.

The is necessary for the digit sum requirement to be enforced. I assume something about doesn't like unknowns, so the tells Brachylog to use a brute-force approach for that part of the program rather than algebra.

user76311

Posted 2017-11-27T09:43:54.207

Reputation:

6

Alice, 35 bytes

/o
\i@/!w?+.?~\ & /-$K..?\ L z $ /K

Try it online!

Explanation

This program has a really nice mix and interaction between Cardinal (integer-processing) and Ordinal (string-processing) mode.

The usual framework for challenges with decimal I/O which operate largely in Cardinal mode:

/o 
\i@/...

And the actual program:

!     Store the input N on the tape.
      We'll use an implicit zero on top of the stack as our iterator variable X,
      which searches for the first valid result.
w     Store the current IP position on the return address stack. This marks
      the beginning of the main search loop. We can avoid the divisibility
      test by going up in increments of N. To check the other two 
      conditions, we'll use individual conditional loop ends that skip to 
      the next iteration. Only if both checks pass and all loop ends are 
      skipped will the search terminate.

  ?+    Increment the iterator X by N.
  .     Duplicate X.
  ?~    Put a copy of N underneath.
  \     Switch to Ordinal mode.
  &     Implicitly convert X to a string, then fold the next command over its
        characters, i.e. its digits. Here, "fold" means that each character
        is pushed to the stack in turn, followed by one execution of that
        next command.
  /     Switch back to Cardinal mode (this is not a command).
  -     Fold subtraction over the digits. This implicitly converts each 
        digit back to its numerical value and subtracts it from N. If the
        digit sum of X is equal to N, this will result in 0.
  $K    Jump back to the w if the digit sum of X isn't N.
  ..    Duplicate X twice.
  ?     Get a copy of N.
  \     Switch to Ordinal mode.
  L     Shortest common superstring. Implicitly converts X and N to strings
        and gives the shortest string that starts with X and ends with N. 
        This will be equal to X iff X already ends with N. Call this Y.
  z     Drop. If X contains Y, this deletes everything up to and including
        Y from X. This can only happen if they are equal, i.e. if X ended
        with N. Otherwise X remains unchanged.
  $     Skip the next command if the string is empty, i.e. if X ended with N.
  /     Switch back to Cardinal mode.
  K     Jump back to w if X didn't end with N.

Martin Ender

Posted 2017-11-27T09:43:54.207

Reputation: 184 808

6

Haskell, 72 bytes

f n=[x|x<-[n,n+lcm n(10^length(show n))..],sum[read[j]|j<-show x]==n]!!0

Try it online!

Note that the found number minus n must be a multiple of both n and 10^length(n).

Inspired by Laikoni and totallyhuman

fishinear

Posted 2017-11-27T09:43:54.207

Reputation: 161

Welcome to the site! – James – 2017-11-27T17:03:54.810

3Change lcm n(10^length(show n)) to lcm(10^length(show n))n for 1 byte – H.PWiz – 2017-11-27T19:52:40.377

5

Java (OpenJDK 8), 136 110 103 92 bytes

-26 thanks to JollyJoker

-7 again thanks to JollyJoker

-11 thanks to Oliver Grégoire

a->{for(int i=a;!(""+a).endsWith(""+i)|i!=(""+a).chars().map(x->x-48).sum();a+=i);return a;}

Try it online!

Gotta love Java! It could well be that I am using an inefficient approach, but not having a built in checksum function and the double conversion to String to check for the end of the number costs bytes...

Ungolfed:

  a->{                                                       //input n (as integer)
      for (int i = a;                                        //initiate loop
           !("" + a).endsWith("" + i)                        //check if the calculated number ends with the input
           | i != ("" + a).chars().map(x -> x - 48).sum();   //check if the checksum is equal to the input
           a += i)                                           //for every iteration, increase i by the input to save checking for divisibility
        ;                                                    //empty loop body, as everything is calculated in the header
    return a;                                                //return number
}

Luca H

Posted 2017-11-27T09:43:54.207

Reputation: 163

1(""+i).endsWith(""+a) should work. – JollyJoker – 2017-11-28T08:28:06.517

@JollyJoker brilliant, thanks for making me feel stupid :P – Luca H – 2017-11-28T08:38:55.523

1Heh. n/=10 instead of n=n/10 too. Also, i+=a in the for loop so you can skip the divisibility check. – JollyJoker – 2017-11-28T08:50:36.287

@JollyJoker wow, I did it for the sum but not for the division... Thank you, I'll add it shortly – Luca H – 2017-11-28T08:54:40.880

98 bytes – Olivier Grégoire – 2017-11-28T10:12:28.413

@OlivierGrégoire Did this before seeing yours, might be possible to combine some tricks. a->{for(int n,s=0,i=a;s!=i|!(""+a).endsWith(""+i);a+=i)for(n=a,s=0;n>0;s+=n%10,n/=10);return a;}; (97 bytes) – JollyJoker – 2017-11-28T10:32:52.660

Yes, I was about to suggest the same without switching i and a

– Olivier Grégoire – 2017-11-28T10:39:03.520

@JollyJoker your solution gives me 3912 for input = 12, don't know why. But Oliver yours is working. Btw: I always included the semicolon in the bytecount, but it makes sense to exclude it, as it is part of the boilerplate and not of the lambda definition – Luca H – 2017-11-28T10:56:49.253

192 bytes, using the API, shorter than calculating yourself. Also, the semicolon is not part of the bytecount because a valid lambda can be given as method argument, for instance and then you don't need that semicolon. – Olivier Grégoire – 2017-11-28T11:06:51.103

@OlivierGrégoire Nice! The (""+a).chars().map(x->x-48) part for getting an IntStream of digits might be handy in the future. – JollyJoker – 2017-11-28T11:34:38.283

@LucaH Well, since it's no longer the shortest, I have a good excuse to skip the debugging :) – JollyJoker – 2017-11-28T11:35:35.577

@OlivierGrégoire I don't think I understand exactly how the checksum part works, but thank you. If one of you two wants to post this as their own submission, I would be happy to revert the changes, as I've got the feeling you did more for the answer than I did... I am just a student with a bit of programming lessons and am still learning a lot, so well... – Luca H – 2017-11-28T12:04:53.170

@JollyJoker You are right :P Just wanted you to know – Luca H – 2017-11-28T12:05:13.863

@LucaH What the "checksum" does is convert the number to a string ((""+a)), stream each character as integers (.chars()), convert the ASCII character (48-57) to their numerical value (0-9) by subtracting 48 from each value (.map(x->x-48)), then sum all those numbers (.sum()). Also, 100 will never work because 99999999999100 is way greater than Integer.MAX_VALUE. – Olivier Grégoire – 2017-11-28T12:28:50.413

@OlivierGrégoire thanks a lot for the explanation, I didn't get the stream part. Pretty clever! – Luca H – 2017-11-28T12:30:46.277

@LucaH Don't worry about taking credit for others' improvements. This is the way it mostly goes in code golf; people suggest improvements until it has nothing in common with the original. – JollyJoker – 2017-11-28T12:43:32.243

@JollyJoker Ok, thank you! – Luca H – 2017-11-28T12:45:36.070

4

Mathematica, 72 bytes

(t=#;While[Mod[t,10^IntegerLength@#]!=#||Tr@IntegerDigits@t!=#,t+=#];t)&  

-18 bytes from @MartinEnder

Try it online!

Here is another version from Martin Ender
This approach can go up to n=40 (41 exceeds the default iteration limit)

Mathematica, 65 bytes

#//.t_/;Mod[t,10^IntegerLength@#]!=#||Tr@IntegerDigits@t!=#:>t+#&

Try it online!

J42161217

Posted 2017-11-27T09:43:54.207

Reputation: 15 931

3

Husk, 20 19 17 bytes

ḟȯ=⁰Σdfȯ€d⁰ṫdm*⁰N

Thanks @Zgarb for -2 bytes!

Try it online!

ბიმო

Posted 2017-11-27T09:43:54.207

Reputation: 15 345

17 bytes by splitting the condition into two. – Zgarb – 2017-11-27T17:53:31.860

3

C (gcc) 71 69 bytes , fails on 100

I tried with long and %1000 but times out

-2 bytes thanks to steadybox

s,i,j;f(n){for(j=0;s^n|j%100!=n;)for(s=0,i=j+=n;i;i/=10)s+=i%10;j=j;}

Try it online

PrincePolka

Posted 2017-11-27T09:43:54.207

Reputation: 653

Learned a new trick today with that j*=1 == return j trick. Nice code. – Michael Dorgan – 2017-11-27T19:51:42.320

https://stackoverflow.com/questions/2598084/function-with-missing-return-value-behavior-at-runtime (last math is returned.) – Michael Dorgan – 2017-11-27T19:54:23.883

@MichaelDorgan assembly of j=j and j*=1

– PrincePolka – 2017-11-27T20:14:00.697

@Steadybox thank you, i will do that – PrincePolka – 2017-11-27T20:16:06.890

3

Python 2, 74 bytes

This solution assumes that n <= sys.maxint.

n=x=input()
while sum(map(int,str(x)))-n*str(x).endswith(`n`):x+=n
print x

Try it online!

FlipTack

Posted 2017-11-27T09:43:54.207

Reputation: 13 242

Replace str(x) with x in back-ticks two times to save 6 bytes (how do you escape back-ticks inside back-ticks?). – Chas Brown – 2017-11-28T09:44:10.763

@ChasBrown ``` backslash tick inside backticks. – wvxvw – 2017-11-28T12:34:15.177

@ChasBrown no, as for long integers that would add an L which could mess up the algorithm. – FlipTack – 2017-11-28T18:37:39.580

2

C# (.NET Core), 90 84 83 + 18 = 101 bytes

using System.Linq;
n=>{for(int i=n;!(""+n).EndsWith(""+i)|n%i>0|(""+n).Sum(c=>c-48)!=i;n++);return n;}

Try it online!

  • 6 bytes saved thanks to Emigna and my uncanny ability to write (""+n) in some places and n.ToString() in others.

Charlie

Posted 2017-11-27T09:43:54.207

Reputation: 11 448

n=>{for(int i=n;n%100!=i|n%i>0|(""+n).Sum(c=>c-'0')!=i;n++);return n;} saves 20 bytes. – Emigna – 2017-11-27T11:28:44.910

@Emigna why n%100? What if n>100? – Charlie – 2017-11-27T11:37:12.253

Oh yeah, ignore that part. That was from testing with 2-digit input. The mod would have to be 10^len(input). Probably not worth it then. – Emigna – 2017-11-27T12:31:17.257

1

Julia, 70 bytes

f(x)=(n=x;while(sum(digits(n))!=x||x!=n%(10^length("$x")));n+=x;end;n)

EricShermanCS

Posted 2017-11-27T09:43:54.207

Reputation: 121

¬x=(n=x;while sum(digits(n))!=x||!endswith("$n","$x");n+=x;end;n) You can save 5 bytes with this. Try it online! – LukeS – 2017-12-22T13:08:08.417

1

Ohm v2, 16 bytes

£^›u³↔ξ³¥s}Σ³E*‽

Try it online!

Cinaski

Posted 2017-11-27T09:43:54.207

Reputation: 1 588

1

Pip, 18 bytes

T!y%a&$+y=aY++i.ay

Algorithm inspired by Emigna's answer. Try it online!

How it works

                    a is 1st cmdline arg, i is 0, y is "" (implicit)
T                   Loop until
 !y%a&              y%a is 0 and
      $+y=a         sum of y is a:
            ++i      Increment i
           Y   .a    and yank (i concat a) into y
                 y  After the loop exits, autoprint y

DLosc

Posted 2017-11-27T09:43:54.207

Reputation: 21 213

1

JavaScript REPL (ES5), 60 59 bytes

for(n=prompt(i=0);eval([].join.call(t=++i+n,'+'))-n|t%n;);t

l4m2

Posted 2017-11-27T09:43:54.207

Reputation: 5 985

@totallyhuman Fixed – l4m2 – 2017-11-28T23:51:12.940

In console it outputs without alert() so I guess – l4m2 – 2017-11-28T23:52:37.477

0

Haskell, 75 bytes

f n=[x|x<-[0,n..],sum[read[d]|d<-show x]==n,mod x(10^length(show n))==n]!!0

Try it online!

Explanation:

f n=[x|                                      ]!!0 -- Given input n, take the first x
       x<-[0,n..],                                -- which is a multiple of n,
                  sum[read[d]|d<-show x]==n,      -- has a digital sum of n
                  mod x(10^length(show n))==n     -- and ends in n.

I wonder whether the "ends in n" part can be shortened. I also tried show n`elem`scanr(:)""(show x), but it's longer.

Laikoni

Posted 2017-11-27T09:43:54.207

Reputation: 23 676

0

Haskell, 75 bytes

f n=[i|i<-[n,n+10^length(show$n)..],i`mod`n<1,sum[read[j]|j<-show$i]==n]!!0

Try it online!

totallyhuman

Posted 2017-11-27T09:43:54.207

Reputation: 15 378

0

Ruby, 65 63 54 53 bytes

->n{a=n;a+=n until/#{n}$/=~a.to_s&&a.digits.sum==n;a}

Try it online!

G B

Posted 2017-11-27T09:43:54.207

Reputation: 11 099

0

Pyth,  22  21 bytes

fq2-/,%T^;l`QsjT;Q%TQ

Try it here!

Mr. Xcoder

Posted 2017-11-27T09:43:54.207

Reputation: 39 774

0

Perl 5, 46 44 + 1 ( -p ) = 45 bytes

2 bytes saved thanks to Xcali, couldn't find better

($\=++$t.$_)%$_|$_-eval$\=~s//+/gr.0&&redo}{

first answer

$\=++$x.$_;eval$\=~s//+/gr."-$_"|$\%$_&&redo}{

Try it online

Nahuel Fouilleul

Posted 2017-11-27T09:43:54.207

Reputation: 5 582

1

Managed to save a couple bytes: Try it online!

– Xcali – 2017-11-27T20:11:18.533

0

PowerShell, 84 bytes

for($n=$i=$args[0];$i%$n-or$i-notmatch"$n$"-or([char[]]"$i"-join'+'|iex)-$n){$i++}$i

Try it online!

Simple construction but lengthy commands. Times out on TIO for n=100, but if we explicitly set i to be close, it outputs correctly.

This is just a simple for loop that keeps going so long as any one of the conditions is true. The three conditions are 1) $i%$n, i.e., we have a remainder; 2) $i-notmatch"$n$", i.e., it doesn't regex match the last couple of digits; and 3) ([char[]]"$i"-join'+'|iex)-$n, i.e., the digits summed together is not equal to $n (here checked by simple subtraction, since nonzero values are truthy). Inside the loop we're simply incrementing $i.

Thus, if we don't have a remainder, the regex matches, and the numbers are equal, all three conditions are $false and we exit the loop. As a result, we just can leave $i on the pipeline, and output is implicit.

AdmBorkBork

Posted 2017-11-27T09:43:54.207

Reputation: 41 581

0

PHP, 73+1 bytes

while(array_sum(str_split($i+=$n=$argn))-$n|$i%10**strlen($n)-$n);echo$i;

Run as pipe with -R.

loops $i through multiples of <input> until sum_of_digits-<input> and tail_of_i-$n are falsy; then prints i.

Titus

Posted 2017-11-27T09:43:54.207

Reputation: 13 814

0

m4, 210 bytes

define(d,define)d(i,ifelse)d(s,`i($1,,0,`eval(substr($1,0,1)+s(substr($1,1)))')')d(k,`r($1,eval($2+1))')d(r,`i(s($2),$1,i(regexp($2,$1$),-1,`k($1,$2)',i(eval($2%$1),0,$2,`k($1,$2)')),`k($1,$2)')')d(f,`r($1,1)')

Defines a macro f which computes the answer. It's a bit slow—unusably so—but I promise it works.

I thought m4 would be nice because it treats integers as strings by default, but this is pretty bad.

Program man

Posted 2017-11-27T09:43:54.207

Reputation: 531

0

Scala, 120 bytes

def a(n:Int)={val b=math.pow(10,math.ceil(math.log10(n))).##;var c=b+n;while(c%n!=0||(0/:c.toString)(_+_-'0')!=n)c+=b;c}

This works until n = 70, after which integers overflow. For one extra character, the Int can change to a Long and allow values for n > 100 to be computed.

Here is the slightly longer ungolfed version:

def golfSourceLong(n: Long): Long = {
  val delta = math.pow(10, math.ceil(math.log10(n))).toInt
  var current = delta + n
  while (current % n != 0 || current.toString.foldLeft(0)(_ + _ - '0') != n) {
    current += delta
  }
  current
}

Martin Tuskevicius

Posted 2017-11-27T09:43:54.207

Reputation: 101

0

R, 115 bytes

function(n,d=nchar(n):1){while(sum(D<-F%/%10^((k=nchar(F)):1-1)%%10)-n|any(D[k-d+1]-n%/%10^(d-1)%%10)|F%%n)F=F+n
F}

Try it online!

Terrible R function. Increments F (starts at 0) by n until a value is found that satisfies the required properties, which it then returns. The use of any on a double expression sends out a warning for each iteration of the loop, but does not affect the correctness.

Times out on TIO for large enough inputs (n=55 or higher) but should correctly compute the solution given enough time/space.

Giuseppe

Posted 2017-11-27T09:43:54.207

Reputation: 21 077

0

Jelly, 22 21 bytes

DS=³a³ḍaDṫ³DLC¤Ḍ=³ø1#

Try it online!

Edit: compressed to a single line

Explanation

DS=³a³ḍaDṫ³DLC¤Ḍ=³ø1#
                  ø1#  Evaluate the condition before this and increment a counter until it is met then output the counter                     
D                      Digits of incremented variable as a list
 S                     Sum
  =³                   Equals argument of program?
    a                  Logical and
     ³ḍ                Does arg divide incremented variable?
       a               Logical and
        Dṫ     Ḍ       Last n digits of inc. var. where n is number of digits in program input
          ³DLC         1 - (number of digits of program input)
              ¤        Book ends above nilad
                =³     Equals program input?

This took me many hours to write because I'm learning Jelly but now that I'm done I'm so satisfied. For a long time I didn't realize I needed the ¤ and I just couldn't get it to work. Looking at [this][1] well explained code helped me seal the deal. Lots of other Jelly answers in PPCG guided me too.

dylnan

Posted 2017-11-27T09:43:54.207

Reputation: 4 993

0

Javascript, 224 bytes function getNumber(x){if(x<12){return!1};const sumDigits=(x)=>x.toString().split('').map(Number).reduce((a,b)=>a+b,0);for(let i=2;i<9999;i++){if((x*i-x)%(Math.pow(10,x.toString().length))==0&&sumDigits(x*i)==x){return x*i}}} Un-golf:

function getNumber(x){
 if (x<12) {return false};
 const sumDigits = (x) => x.toString().split('').map(Number).reduce((a,b)=>a+b, 0);
 for (let i=2; i<9999; i++){
  if((x*i-x)%(Math.pow(10, x.toString().length))==0 && sumDigits(x*i)==x){
   return x*i;
}
}
}

Usage: 1. getNumber(12) 2. getNumber(13) 3. ....

NTCG

Posted 2017-11-27T09:43:54.207

Reputation: 151

I don't know much about Javascript golfing, but I'm pretty sure you should shorten the names getNumber or sumDigits. – Ørjan Johansen – 2017-12-04T09:45:48.087

Thank you so much, I am not go to win here, just want to get into this challenge :smile: – NTCG – 2017-12-07T04:35:38.783

0

J, 37 33 bytes

+^:(((=1#."."0)*:(e.".\.))":)^:_~

Try it online!

                                ~    A = N
+^:                          ^:_     while(...)A+=N; return A
   (                      ":)        A to string
   (((    "."0)          )  )        digits of A
   ((( 1#.    )          )  )        sum
   (((=       )          )  )        equals N
   ((            (e.".\.))  )        N is one of the suffixes of A-string
   ((          *:        )  )        not AND

Prepending the iteration counter is ~5 times faster but 5 bytes longer:

(]+[((=1#.,.&.":)<:|),~&.":)^:_&1,&":]

Try it online!

Incrementing by 100, 27 bytes:

(]+100*(=1#.,.&.":)<:|)^:_~

Try it online!

FrownyFrog

Posted 2017-11-27T09:43:54.207

Reputation: 3 112

0

Python 2, 70 bytes

f=lambda n,x=0:x*(x%n<sum(map(int,`x`))==n==x%10**len(`n`))or f(n,x+n)

Try it online!

Cowabunghole

Posted 2017-11-27T09:43:54.207

Reputation: 1 590