Page 2 of 3
Posted: Thu Apr 15, 2004 8:21 am
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
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
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
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.
--

Posted: Sun Apr 18, 2004 12:15 pm
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
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
dunno why
i got WA too...

Posted: Wed Jul 14, 2004 3:02 pm
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
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
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
send me your pascal program also.

Posted: Thu Oct 07, 2004 2:08 pm
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
WTF!

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

Posted: Sat Mar 12, 2005 6:16 pm
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
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.
--