Page 2 of 2

Re: Problem 064

Posted: Wed Jul 08, 2015 8:45 am
by srinathmkce
I used python programming and am getting right answer for N <=13 and also the below 4 numbers are giving me the correct numbers.

9993: 94
9994: 70
9995: 4
9996: 4
9997: 59

So, i assume my logic is correct and i guess my incrementing stuff is going wrong . Bcoz PE is showing my answer as incorrect.

Just to add clarity of what i did .

<algorithm removed by moderator>

But, my final answer is not correct. Not sure why . Is there any flaw in my approach ?

Re: Problem 064

Posted: Wed Jul 08, 2015 2:05 pm
by mpiotte
srinathmkce wrote:...But, my final answer is not correct. Not sure why . Is there any flaw in my approach ?
It is inappropriate to post your algorithm here, whether or not it works.
If you send me a PM with the period length that you find for the different values of n, I'll compare it with my own list.

Problem 64: what am I doing wrong?

Posted: Wed Apr 18, 2018 6:52 pm
by Omri_Shavit
Hi,
When doing problem 64, Odd period square roots, I got the incorrect answer XXX. So, I began manually checking some of the continued fractions that my code spat out with www.wolframalpha.com. Oddly enough (no pun intended), I couldn't find any that were wrong, and I also couldn't find any whose period was labeled even/odd incorrectly either. Please help.

P.S. I'll PM you a text file of what my code outputs (don't know if I should post it here b/c spoilers):

It looks like this:
x: sqrt(x): period length: current # of odds:
1 --> 1 --> DNE (rational) --> 0
2 --> [1;(2)] --> 1 = odd (+) --> 1
3 --> [1;(1,2)] --> 2 = even --> 1
4 --> 2 --> DNE (rational) --> 1
5 --> [2;(4)] --> 1 = odd (+) --> 2
6 --> [2;(2,4)] --> 2 = even --> 2
7 --> [2;(1,1,1,4)] --> 4 = even --> 2
8 --> [2;(1,4)] --> 2 = even --> 2
9 --> 3 --> DNE (rational) --> 2
10 --> [3;(6)] --> 1 = odd (+) --> 3
11 --> [3;(3,6)] --> 2 = even --> 3
12 --> [3;(2,6)] --> 2 = even --> 3
13 --> [3;(1,1,1,1,6)] --> 5 = odd (+) --> 4
...
Later values removed by moderator.

as you can see, somewhere it gets it wrong :/

Re: Problem 064

Posted: Wed Apr 18, 2018 7:32 pm
by RobertStanforth
Dear Omri_Shavit,
I moved your post to the existing clarification thread for this problem.
Based on your workings for the first 13 cases, you understand the problem statement correctly.
Moreover, the continued fraction you provided for 9999 was correct - but your overall answer was much too low.

Re: Problem 064

Posted: Thu Apr 19, 2018 3:00 pm
by Omri_Shavit
Dear RobertStanforth,
Thank you for replying. I finally got it! My mistake was embarrassingly simple: I originally capped the algorithm at 30 iterations for testing purposes (so it would not go on forever if I was doing something wrong). Once I got the algorithm working, I neglected to remove the 30-iteration limit which resulted in it setting every period greater than 30 to 30 --> even. That's why many odd-period fractions were not counted.
Thanks again,
Omri Shavit