Page **2** of **3**

Posted: **Thu Apr 15, 2004 8:21 am**

by **Dominik Michniewski**

From ranklist I suppose, that exist way to not hard-code 2k-digits automorhic number, but generating it in program. Can anyone help me and tell me how can I do this ? Unfortunatly I got Accepted using hard-coded number. I don't like such way (this is first program in which I made it

- I always want to find way in which I can generate data in program ... ).

If anyone can help me - please send me a hint. I know that I can generate number in such way (but It got TLE):

1. get the number of N digits, for examle 5

2. generate number xN, using following algorithm:

3. try every digit 0..8 for x and calculate sqrt(xN); if sqrt(xN) has the same all digits at the end of xN this is good number and go to 2

If I correct think, this algorithm has time complexity O(NlogN) where N is number of digits.

Best regards

DM

Posted: **Sat Apr 17, 2004 8:00 am**

by **anupam**

*One thing I can say to DM,*

I have solved the problem by precalculation.

First generate all the numbers ending with 5 and then 6.

A great property of automorphic number is that,

antumorphic number of (n+1) digit ending with 5/6 contains automorphic number of n digits ending with 5/6.

To be clear,

5

25

625

x625

yx625

zyx625

So, you need not to check the other digits..

What you need is to add 1-9 and check whether the number is automorphic and if this is, break there.

means,

25-automorphic

125-no

225-no

325-no

425-no

525-no

625-automorphic break;

try with 1625

2625

similarly..

After precalcultion you need to store two array of character,

one for ending with 6, another ending with 5.

Then for each query just use strcmp, or strstr type functions in c or c++;

--

Hope it will be clear to all of you.,..

Good day

Posted: **Sat Apr 17, 2004 7:05 pm**

by **Dominik Michniewski**

yes, it's clear to me anapum

but when I use such way, I got TLE

Maybe I do something wrong ?

Best regards

DM

Posted: **Sun Apr 18, 2004 5:06 am**

by **yahoo**

*you need not calculate the whole array for checking automorphic number..*

For example,

25

25

---625

save the result and extend it for

625

625

--

do not calculate 25*25 again, just extend it for the last 6.

--

hope i am clear.. and it will help you..

Posted: **Sun Apr 18, 2004 12:15 pm**

by **Dominik Michniewski**

Thanks yahoo, now I know what I'm doing wrong

Nobody is perfect, but it's very nice, that still exist persons, which have fresh ideas for me

Best regards

DM

Posted: **Sun Jul 11, 2004 8:47 am**

by **cytmike**

I used both the method of hard-code and check them one by one.

But I got both WA. Can anybody tell me why? Is there trciky cases besides 0 and 1?

I wonder if "0000" or "001" is correct?

Posted: **Sun Jul 11, 2004 6:43 pm**

by **cytmike**

dunno why

i got WA too...

Posted: **Wed Jul 14, 2004 3:02 pm**

by **cytmike**

Finally, i got AC when I translate my program from c++ to pascal...

Does anyone got any idea why this occur?

Posted: **Thu Jul 15, 2004 5:05 pm**

by **anupam**

*I don't face any problem with c++.*

In c++ you can ac the program by having an array of 2500 dig and then by searching the array only.

Just a code of 5 lines I think:-)

BTW, would you plz mention the problem you faced with c++?

--

Posted: **Thu Jul 15, 2004 5:50 pm**

by **cytmike**

anupam wrote:*I don't face any problem with c++.*

In c++ you can ac the program by having an array of 2500 dig and then by searching the array only.

Just a code of 5 lines I think:-)

BTW, would you plz mention the problem you faced with c++?

--

I got WA in c++.

Let me pm my code to u~

Posted: **Sat Jul 17, 2004 6:33 pm**

by **anupam**

send me your pascal program also.

Posted: **Thu Oct 07, 2004 2:08 pm**

by **jackie**

I suffered the same problem and got many WAs.

After that i realized the 2000 digits long const char array may cause the problem.

Just use "\" to break the long line, i get AC.

ie.

char r5[MAX+10] = "0302695456948792438016548848805106486276062082716415\

91325236097905009383854054263247198939318022098236001625451776810291593965045\

06657809033052772198385286341879645511424748536307235457049044509125214234275\

I think it may be the compiler's fault.

Anyone who knows why the compiler makes the program WA please "Private Message" to me(i can get it from the e-mail).

hope it will help.

Good luck.

Posted: **Wed Oct 13, 2004 11:52 pm**

by **[RiS]**

WTF!

I had the same error.

I broke the strings with "\" and I get AC.

Posted: **Sat Mar 12, 2005 6:16 pm**

by **Ryan Pai**

I just wanted to clarify, if the number given is zero or one, then the judge considers it automorphic only if it has no leading zeros (in particular 0 and 01 are not an automorphic numbers). My program considers 1 to be an automorphic number, but I don't know if the judge has such a case.

Posted: **Fri May 18, 2007 6:35 pm**

by **Deno**

yahoo wrote:*you need not calculate the whole array for checking automorphic number..*

For example,

25

25

---625

save the result and extend it for

625

625

--

do not calculate 25*25 again, just extend it for the last 6.

--

hope i am clear.. and it will help you..

This is helpful but it's not enough to get AC.

Here is the reason:

When we extend 25 to x25, we still have to multiply 25 by x!

Let y equal to 25. Then multiplying x25 * x25 is equal to ...

(100x + y) * (100x + y) = 10000x^2 + 200yx + y^2

y^2 is taken cared of and 10000x^2 is easy to compute. However, see the middle term 200yx. Every single digit of y still has to multiply with x and 2!! As y is can be as large as 2000 digits, more has to be done to reduce the time.

Does anyone have any more hints??

Thanks