Domino,
First, thank you for the support.
Although the algorithm is apparently not so good
in terms of performance.
Second,
Code: Select all
Well, it seems you figured it out that tests like 20 and 2000 weren't working because you didn't treat the case when the phi_n = p^k*(p-1) (p prime) and the minimal n could have been p^(k+1) (it's not always p^(k+1) as you realised that for 32 it was 51).
The answer is : yes, I realised that.
Third,
16842752 = 2^8 * 257*256
is the answer to my question
"what is so special about this number ? "
Of course your explanations which follow
make it even more clear.
I will try to fully understand them and implement them
somehow
As far as I understand :
let's say you do this
res1 = calc_N_from_PHI_N(J) ;
res2 = calc_N_from_PHI_N(num/J);
1) If res1 and res2 have no common divisor than
we have no problem. In this case we
generate res1*res2 and we put it in the list of
our candidates for N ( whose phi(N)==num ) .
2) If they have common divisor - than what ?!
I think in that case you assume that J has the form
(p^k) * (p-1) and you do this : assign p^(k+1) to res1
( res1 = p^(k+1) )
So ...
I. You actually generate a second candidate for res1
after the first one has failed due to the reason it has
a common divisor with res2 ?! Right ?
And then you put res2 * res1 in the list of your candidates.
( and that is the difference with what I do not - I would simply
reject it as gcd(res1, res2) != 1 )
Is that what you meant ?!
Or ...
II. maybe you check all numbers between
res1 and p^(k+1) in the case when res1 and res2 have
common divisor > 1 ?! I mean you calculate their PHI and you
check if it is equal to J ?!
This option No.II sounds less probable to me.
As you can see I'm slightly stupid so I need some more
explanations
By the way I am not sure "our algorithm" is always correct.
I mean mathematically. It's a sort of a heuristic algorithm.
This explains the fact I have WA. Maybe the judge should
give ACC for programs which generate correct answers
for 90% of the test cases
