## 913 - Joana and the Odd Numbers

Moderator: Board moderators

### 913 - Joana and the Odd Numbers

Do i need to precalculate??
how i determine the 1st integer of the line N ????
sakhassan
Experienced poster

Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

No need to precalculate anything. You can find a general formula to find the last integer in the line N. First list all the numbers -

Line 1 - 1
Line 3 - 7
Line 5 - 17
Line 7 - 31
Line 9 - 49
Line 11 - 71
...
Line N - ?

The formula is not so tough. Try it.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

Thanks J@N.... I got the formula
sakhassan
Experienced poster

Posts: 105
Joined: Sat Mar 11, 2006 9:42 am
Location: cse,DU

can anyone tell me whats the wrong with my code?
Last edited by kana on Tue Nov 28, 2006 9:54 pm, edited 1 time in total.

kana
New poster

Posts: 19
Joined: Mon Mar 13, 2006 6:03 pm
Location: dhaka

Try the samples

Input:
Code: Select all
`999999991000000001`

Output:
Code: Select all
`149999999999999911500000005999999997`

Use 'long long' istead of 'long double'. Dont forget to remove your code. And remember that if you want to post a code then paste your code using 'code' from the editor. Hope these help.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

### 913...TLE!!!!

can anyone expain why i am getting TLE for this code

Code: Select all
`CUT`

plzzzzzzzzzz help me!!!
thanx
Last edited by Iffat on Mon Dec 04, 2006 1:17 pm, edited 1 time in total.
Iffat
New poster

Posts: 25
Joined: Sat Jul 22, 2006 9:47 am

Read the previous posts and run your code with those samples. You will find the reason yourself.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

thanx for reply..but i am still confused ...i used long long...will u explain my bug plzz?
Iffat
New poster

Posts: 25
Joined: Sat Jul 22, 2006 9:47 am

'long long' is not the problem.
Code: Select all
`      while(n!=1)       {          sum=sum+(n*2);          n-=2;       }  `

If the value of 'n' is big, like 1000000001, then you have to use this loop for (1000000001/2) times. Which is too big. Try to figure out the last odd number in a certain line. You dont have to use any loop. You can find a general formula. Then the result can be found in just O(1) time, which means no loop. Hope you can generate the formula.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

thanx jan i got the formula and got AC
Iffat
New poster

Posts: 25
Joined: Sat Jul 22, 2006 9:47 am

### why wa?

Code: Select all
`removed after accept`
Last edited by rezaeeEE on Thu May 24, 2007 9:54 pm, edited 1 time in total.
rezaeeEE
New poster

Posts: 25
Joined: Fri May 11, 2007 3:45 pm

functoin pow() returns double, and you are assigning it to a 'long long' variable. So, precision problems can occur easily. Try to get rid of floating point calculations.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

### thank u

thank u very much mr jan.
you are a great helper.
rezaeeEE
New poster

Posts: 25
Joined: Fri May 11, 2007 3:45 pm

Code: Select all
`deleted after AC`

i get RE for this...can anyone help me? thx
Last edited by laicc86 on Thu Oct 25, 2007 6:59 pm, edited 1 time in total.
laicc86
New poster

Posts: 5
Joined: Sun Oct 07, 2007 6:52 pm

The input set contains valid cases. So, no need to check n. And the function should be

Code: Select all
`long long odd_num(long long num)`

Hope these help.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm