913 - Joana and the Odd Numbers

All about problems in Volume 9. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

913 - Joana and the Odd Numbers

Post by plamplam »

Hi, can anyone please help me here? I know this is a very easy problem and I could easily find the relation(there is a sequence) and found out the last term. And then sum of the last three terms would be (last term * 3) - 6.
The judge keeps giving me Wrong Answer for apparently some strange reason, I can't figure this out so may be a little help?? Thanks a lot guys.....Im pasting my source code below:

#include <stdio.h>
#include <math.h>
int main()
{
double t, i, j, k, l, x, y, z, sum, a, d;
long long int n;

for (; ;)
{
if (scanf("%lld", &n) == EOF)
break;
if (n <= 1)
break;
if (n % 2 == 0)
break;

sum = 0;
a = 6;
x = ( (n - 1) / 2.0);
y = (x / 2.0) * (12.0 + ( (x - 1) * (4.0) ) );
sum = (3 * y) - 3;
printf("%0.0lf\n", sum);
}
return 0;
}
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

913 - Joana and the Odd Numbers

Post by plamplam »

#include <stdio.h>
#include <math.h>

int main()
{
long long int y, t, i, j, k, l, z, a, d, n, sum;
double x;

while (scanf("%lld", &n) == 1)
{
x = ( (n - 1) / 2.0);
y = (x / 2.0) * (12.0 + ( (x - 1) * (4.0) ) );
sum = (3 * y) - 3;
printf("%lld\n", sum);
}
return 0;
}
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

zobayer
Experienced poster
Posts: 110
Joined: Tue May 06, 2008 2:18 pm
Location: CSE-DU, Bangladesh
Contact:

Re: 913 - Joana and the Odd Numbers

Post by zobayer »

Please search the forum with 913 first, and post in appropriate section.
You should not always say what you know, but you should always know what you say.

Post Reply

Return to “Volume 9 (900-999)”