+ 48
Challenge : Automorphic Number
An automorphic number, also known as an automorph, is a number n whose square ends in n. For instance 5 is automorphic, because 5*5 = 25, which ends in 5. Write a code that shows all the Automorphic Numbers from 1 up to n.
63 Answers
+ 21
I made the code in c++: https://code.sololearn.com/cx1cYBlw64KP
And I calculated 18 automorphic numbers:
1: 1
2: 5
3: 6
4: 25
5: 76
6: 376
7: 625
8: 9376
9: 90625
10: 109376
11: 890625
12: 2890625
13: 7109376
14: 12890625
15: 87109376
16: 212890625
17: 787109376
18: 1787109376
I think, there are two numbers in range between 10^n and 10^(n-1) and these numbers end with the same digits. If so, I wrote the code supported big numbers: https://code.sololearn.com/ce5RV8P5vpTc
It calculate so many numbers as you want.
Update: the numbers are sorted in ascending order
+ 22
+ 18
JavaScript:
var a = prompt("") - 0;
if (((a * a) + "").endsWith(a + ""))
alert(a + " is an Automorphic Number.");
+ 14
here's my one-liner in Python 🐍
https://code.sololearn.com/cR9oOEFPW4J1/?ref=app
+ 12
Here is Mine.
https://code.sololearn.com/cBW1YLU3TiC0/?ref=app
+ 11
https://code.sololearn.com/c5x0Du9pyDij/?ref=app
+ 10
https://code.sololearn.com/c9QvMV9wTZgO/?ref=app
+ 10
here's my try
used @yash's algorithm.
https://code.sololearn.com/cBUaUG6DrWu3/?ref=app
+ 10
Thanks for the challenge.
Here's my try in one line...
https://code.sololearn.com/cAFYbiP4l9Jd/?ref=app
+ 9
@Yash Thanks for the algorithm!
+ 9
Here is my code.. I tried it and it turns out there are very few of them.
https://code.sololearn.com/W73HoO96jX8b/?ref=app
+ 9
My try in Java:
https://code.sololearn.com/cBkUW8dD8SxY/?ref=app
+ 9
Here is mine. Large Ns (here 12345678901234567890123456789) without problem thanks to the method that 'grow' the numbers list. Also can give you the Kth automorphic (works for k=1000 which has 563 digits and larger values) https://code.sololearn.com/cm760dHg3ELr/?ref=app
Here is the 1800th automorphic number calculated with this code:
701117131278125400133690086034889084364023875765936821979626181917833520492704199324875237825867148278905344897440142612317035699548419499444610608146207254036559998271588356035049327795540741961849280952093753026852390937562839148571612367351970609224242398777007574955787271559767413458997537695515862718887941516307569668816352155048898271704378508028434084412644126821848514157729916034497017892335796684991447389566001932545827678000618329854426232827257556110733160697015864984222291255485729879337147866323172405515756102352543994999345608083801190741530060056055744818709692785099775918050075416428527708162011350246806058163276171676765260937528056844214486193960499834472806721906670417240094234466197812426690787535944616698508064636137166384049029219341881909581659524477861846140912878298438431703248173428886572737663146519104988029447960814673760503957196893714671801375619055462996814764263903953007319108169802938509890062166509580863811000557423423230896109004106619977392256259918212890625
+ 7
Krishna's code, but in Python😊
https://code.sololearn.com/c1q37ou0Y8b6/?ref=app
+ 7
nice one @yash