Page 3 of 3

913 - Joana and the Odd Numbers

Posted: Mon May 23, 2011 3:59 pm
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;
}

913 - Joana and the Odd Numbers

Posted: Tue May 24, 2011 6:29 pm
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;
}

Re: 913 - Joana and the Odd Numbers

Posted: Mon Jun 13, 2011 12:43 am
by zobayer
Please search the forum with 913 first, and post in appropriate section.