## 138 - Street Numbers

Moderator: Board moderators

_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

### Thanks!.

Greetings.
Thanks!, I will.
_.

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am
You could lookup "Pell's equation" at mathworld.wolfram.com.

One can solve this equation using continued fractions (square root of 2 in this case).

Using this solution I got an even better timing than just printing the pre-calculated results!

_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

### Good maths.

Thanks!.
Will take a look to it
Keep posting!.
_.

sunmoon
New poster
Posts: 4
Joined: Tue Jun 29, 2004 12:50 pm
Contact:

### Try using this relation

Consider the equations,
y^2 - 2x^2=1 ; 2y^2-x^2=1

If (a,b) is a solution to one of the above equations,
then (3a+4b,2a+3b) is also a solution.

Hope you get it!!
All

ravi,IITM.

Erik
Learning poster
Posts: 67
Joined: Fri Jul 01, 2005 11:29 am
Location: Germany
Contact:

### 138: WA

Hi,

I got the solution for problem 138 and I'm sure it is right.
That's as all outputs obey the desired property and they correspond with the outputs given on other threads.

Could anyone who solved this problem please check my solution? I could send it as private message.

Cu, Erik

Erik
Learning poster
Posts: 67
Joined: Fri Jul 01, 2005 11:29 am
Location: Germany
Contact:

After many hours of testing I finally realized that I messed up the I/O.
On my machine I work with files for acm and hence use conditional compilation. I messed that up so it worked for me but not the judge.

andysoft
Experienced poster
Posts: 109
Joined: Sat Jun 23, 2007 9:53 pm
Location: Brest, BELARUS
Contact:
Hi people!
I have a question.
I am submitting my prog for many times, but judge still says "WA". My output is the following (except spaces added by 'code' tag in the end of line):

Code: Select all

``````         6         8
35        49
204       288
1189      1681
6930      9800
40391     57121
235416    332928
1372105   1940449
7997214  11309768
46611179  65918161
``````
I am sure this is correct, but how do I get WA??
Now I lay me down to sleep...
my profile

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Contact:
Your outputs are correct. Remove them. Submit again.
Ami ekhono shopno dekhi...
HomePage

apurba
New poster
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm

### problem no 138--help pls

why getting wa?
someone pls check that out.
here is my code.......

Code: Select all

``````

``````
help pls.
Last edited by apurba on Sun Dec 30, 2007 7:03 pm, edited 1 time in total.

Code: Select all

``keep dreaming...``

ovidiu
New poster
Posts: 10
Joined: Fri Dec 07, 2007 10:42 am
Your code displays many times the same pair, like:

Code: Select all

``````         6          8
6          8
6          8
6          8
6          8
...
``````

apurba
New poster
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm
ovidiu wrote:Your code displays many times the same pair, like:

Code: Select all

``````         6          8
6          8
6          8
6          8
6          8
...
``````
i have noticed that my code gives 3 correct output but repeat them.
why this is happening?

Code: Select all

``keep dreaming...``

ovidiu
New poster
Posts: 10
Joined: Fri Dec 07, 2007 10:42 am
Because you have the lines:

Code: Select all

``````long count=0;
if(count==10)
``````
count will always be 0 in this if ...

It seems it is important that you learn to debug the code.
Set a breakpoint at line:
count++;
and watch the variable i.

apurba
New poster
Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm

### fed up with the problem

ovidiu wrote:Because you have the lines:

Code: Select all

``````long count=0;
if(count==10)
``````
count will always be 0 in this if ...
it works.
but now i am getting only 5 outputs.
and it is working too slow.
thanks for ur help..........
here is my updated code.........

Code: Select all

``````
``````
i m really fed up with this problem!!!!!!!!!!!!!!!!!!!
Last edited by apurba on Mon Dec 31, 2007 7:21 am, edited 1 time in total.

Code: Select all

``keep dreaming...``

ovidiu
New poster
Posts: 10
Joined: Fri Dec 07, 2007 10:42 am
Think if you really need to compare temp1 with n.

WAandAC
New poster
Posts: 4
Joined: Sat Nov 03, 2007 4:32 am

### Re: problem no 138--help pls

Hi,

I think this is an easy problem, but why i get wa?

Here is my code

Code: Select all

``````#include <iostream>
using namespace std;
int main ()
{
int l1 [10] = {6, 35, 204, 1189, 6930, 256, 7742, 11707, 19813, 25162};
int l2 [10] = {8 ,49, 288, 1681, 9800, 131072, 131528, 132113, 134033, 135816};
for ( int i = 0; i < 10; i++)
{
printf ("%10d%10d\n", l1[i], l2[i]);
}
return 0;
}
``````
Here is my output

Code: Select all

``````         6         8
35        49
204       288
1189      1681
6930      9800
256    131072
7742    131528
11707    132113
19813    134033
25162    135816
``````
Can anyone help me? Thank you!