1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10433 (Automorphic Numbers)
*
* @author David Leib
* @author Julius Tschannerl
* @version 1.0, 04/08/2009
*
* Programm fürs Generieren großer automorphischen Zahlen
*/

import java.math.BigInteger;

public class BigAutomorphicNumbers {

public static void main (String... args)
{
StringBuilder end5 = new StringBuilder("25");
StringBuilder end6 = new StringBuilder("76");
BigInteger bi6 = new BigInteger("123");
BigInteger bi5 = new BigInteger("123");
String square = "ignore";

while (end5.length() < 2000)
{
end5.insert(0, '0');
for (int i = 0; i <= 9 && !(square.endsWith(end5.toString())); i++)
{
end5.replace(0, 1, Integer.toString(i));
bi5 = new BigInteger(end5.toString());
square = (bi5.multiply(bi5).toString());
}
}

System.out.printf("Automorphic Number ending with 5: %n%n%s", end5.toString());
System.out.printf("%n----------------------------------%n");

while (end6.length() < 2000)
{
end6.insert(0, '0');
for (int j = 0; j <= 9 && !(square.endsWith(end6.toString())); j++)
{
end6.replace(0, 1, Integer.toString(j));
bi6 = new BigInteger(end6.toString());
square = (bi6.multiply(bi6).toString());
}
}

System.out.printf("Automorphic Number ending with 6: %n%n%s", end6.toString());
}
}




/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #10433(Automorphic Numbers)
*
* @author David Leib
* @author Julius Tschannerl
* @version 1.0, 04/08/2009
*
* Status : Accepted
* Runtime: 0.330
*/



import java.io.*;

public class Main {

public static boolean isAutomorphic(String number)
{
/*if (number.equals("1"))
return true;*/

String end5 = "2603026954569487924380165488488051064862760620827164159132523609" +
"7905009383854054263247198939318022098236001625451776810291593965" +
"0450665780903305277219838528634187964551142474853630723545704904" +
"4509125214234275955491843973984458712528694819826927029255264834" +
"9032065268512722029613186999477765354812915198576404229681830917" +
"7344527772320073760382588317272927956365741901444523595431910306" +
"3572496178988203175787761062137708080967811374931911766563031490" +
"2057843525095728806684641210692528022750612985116162063840067789" +
"7940244902387511125868953454951488820067866770234100283954928297" +
"0286447273625217535443197911855068157264858804852673871684804002" +
"1885294730222233445412213284648441535937936631336044589403287234" +
"7840194735756036134621200867537334691331433871735088021260028575" +
"2985386643931022326553454776845029957025561658143370236502074744" +
"8568147878729020924125829053012491246688683515876774998917686787" +
"1572813494087927689452979709777230540335661882819870221063055796" +
"7239806611190197744642421025136748701117131278125400133690086034" +
"8890843640238757659368219796261819178335204927041993248752378258" +
"6714827890534489744014261231703569954841949944461060814620725403" +
"6559998271588356035049327795540741961849280952093753026852390937" +
"5628391485716123673519706092242423987770075749557872715597674134" +
"5899753769551586271888794151630756966881635215504889827170437850" +
"8028434084412644126821848514157729916034497017892335796684991447" +
"3895660019325458276780006183298544262328272575561107331606970158" +
"6498422229125548572987933714786632317240551575610235254399499934" +
"5608083801190741530060056055744818709692785099775918050075416428" +
"5277081620113502468060581632761716767652609375280568442144861939" +
"6049983447280672190667041724009423446619781242669078753594461669" +
"8508064636137166384049029219341881909581659524477861846140912878" +
"2984384317032481734288865727376631465191049880294479608146737605" +
"0395719689371467180137561905546299681476426390395300731910816980" +
"2938509890062166509580863811000557423423230896109004106619977392" +
"256259918212890625";
String end6 = "7396973045430512075619834511511948935137239379172835840867476390" +
"2094990616145945736752801060681977901763998374548223189708406034" +
"9549334219096694722780161471365812035448857525146369276454295095" +
"5490874785765724044508156026015541287471305180173072970744735165" +
"0967934731487277970386813000522234645187084801423595770318169082" +
"2655472227679926239617411682727072043634258098555476404568089693" +
"6427503821011796824212238937862291919032188625068088233436968509" +
"7942156474904271193315358789307471977249387014883837936159932210" +
"2059755097612488874131046545048511179932133229765899716045071702" +
"9713552726374782464556802088144931842735141195147326128315195997" +
"8114705269777766554587786715351558464062063368663955410596712765" +
"2159805264243963865378799132462665308668566128264911978739971424" +
"7014613356068977673446545223154970042974438341856629763497925255" +
"1431852121270979075874170946987508753311316484123225001082313212" +
"8427186505912072310547020290222769459664338117180129778936944203" +
"2760193388809802255357578974863251298882868721874599866309913965" +
"1109156359761242340631780203738180821664795072958006751247621741" +
"3285172109465510255985738768296430045158050055538939185379274596" +
"3440001728411643964950672204459258038150719047906246973147609062" +
"4371608514283876326480293907757576012229924250442127284402325865" +
"4100246230448413728111205848369243033118364784495110172829562149" +
"1971565915587355873178151485842270083965502982107664203315008552" +
"6104339980674541723219993816701455737671727424438892668393029841" +
"3501577770874451427012066285213367682759448424389764745600500065" +
"4391916198809258469939943944255181290307214900224081949924583571" +
"4722918379886497531939418367238283232347390624719431557855138060" +
"3950016552719327809332958275990576553380218757330921246405538330" +
"1491935363862833615950970780658118090418340475522138153859087121" +
"7015615682967518265711134272623368534808950119705520391853262394" +
"9604280310628532819862438094453700318523573609604699268089183019" +
"7061490109937833490419136188999442576576769103890995893380022607" +
"743740081787109376";

if (end5.endsWith(number) || end6.endsWith(number))
return true;
return false;
}

public static void main(String... args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String number = br.readLine();
while (number != null){
number.trim();
if (!isAutomorphic(number))
System.out.println("Not an Automorphic number.");
else
System.out.printf("Automorphic number of %d-digit.\n", number.length());
number = br.readLine();
}
br.close();
System.exit(0);
}
}