Page 1 of 3

### 10025 - The ? 1 ? 2 ? ... ? n = k problem

Posted: Wed Jun 12, 2002 7:30 pm
The problem description doesn't say that the first input is the number
of items to process! Please fix this!

-Chris

Posted: Wed Jun 12, 2002 7:48 pm
Calm down, - the problem is clearly marked as being multiple input by a blue checkmark.

### Doh!

Posted: Wed Jun 12, 2002 11:20 pm
Many apologies - I'm new here, and hadn't realized the multiple input
condition at all! It'd be nice if this was mentioned in the problems
themselves, e.g. Note: multiple input (with link to the page describing
the multiple input condition). It's certainly a small thing, but it would
save people from wasting time, and all the input/output conditions would
be in the actual problem description. -Chris

### 10025

Posted: Wed Nov 20, 2002 3:11 am
Can you tell me if the following input and output datas are right?

Thank you!

Input Output
-----------------------------------------
1000000000 44723
43562436 9335
-235344 687
0 3
234387 685
------------------------------------------

Can you send some of your datas to me ?

Bye!

### 10025

Posted: Sun Nov 24, 2002 4:51 pm
Okay I have fixed 2 major bugs: (1)realizing multiple input and (2)recognizing output=3 for input=3. But I still get WA...any help folks?

[cpp]

#include <iostream.h>
#include <stdlib.h>
#include <math.h>

int main()
{
int numcases;
cin >> numcases;
for(int i=0; i<numcases; i++)
{
unsigned number, temp;
double root;
unsigned root2;
cin >> number;
number = abs(number);
if(number == 0)
root2 = 3;
else if(number == 1)
root2 = 1;
else
{
temp = 2 * number;
root = sqrt(temp);
root2 = (root == (int)root) ? (int)root : (int)root+1;
while(true)
{
if((root2*(root2+1)/2 - number)%2 == 0)
break;
root2++;
}
}
cout << root2 << "\n";
}
return 0;
}[/cpp]

Posted: Mon Dec 09, 2002 2:00 pm
Input Output
-----------------------------------------
1000000000 44723
43562436 9335
-235344 687
0 3
234387 685
------------------------------------------

This output is correct. If you get WA, maybe you don't consider the multiple input.

Posted: Wed Dec 25, 2002 3:06 pm
Your program doesn't produce the correct output for k=3. Output should be 2 (1+2 = 3) but your program answered 5 when I tried it.

Posted: Thu Dec 26, 2002 4:41 am
Incredible thanks. Turns out my program doesn't work not only for input=3, but for input=any triangular number (3, 6, 10, 15...).
Writing test cases is a skill I need to master.

Posted: Wed Jan 15, 2003 7:01 pm
I solved the problem and it works for all inputs that I can find (here or in the problem...) but I still receive WA. Can you tell what can be wrong?

Carmen

Posted: Thu Jan 16, 2003 11:36 am
I solved the problem and it works for all inputs that I can find (in board or in the problem...) but I still receive WA. Can you tell what can be wrong?

[c]
deleted
[/c]

Posted: Thu Jan 16, 2003 11:48 am
It's a multiple input problem (blue check mark). You should read http://acm.uva.es/problemset/minput.html to find out what the input and output should look like. The first line of input contains the number of cases, and there should be a blank line between each output case.

Posted: Thu Jan 16, 2003 2:11 pm
That was so useful hint for me. Thanks a lot because I was sure that the algorithm it's Ok but . . .

I was accepted now

### 10025

Posted: Mon Jan 20, 2003 3:15 pm
[cpp]
#include <iostream.h>
#include <stdio.h>
void main(void){
int number,i,base,different,state;

while(1)
{

i=0;
base=0;
state=0;

cin>>number;
if (feof(stdin)) break;
if (number < 0)
number=-number;
while(1)
{
i++;
base+=i;
if (base>=number)
{
different=base-number;
if ((different==0)||(different % 2==0))
{
break;
}
}

}
if (number==0)
cout<<3<<endl;
else
{
cout<<i<<endl;
}
}
}

[/cpp]
i get a WA, pls help help me....

Posted: Tue Jan 21, 2003 5:27 am
pc5971 wrote:I was sure that the algorithm it's Ok
Can you show me how does your algorithm work?
My math is not good. Thanks.

Posted: Tue Jan 21, 2003 8:05 am
I deleted the code, I think you can understend why... but I'll try to explain my algorithm...

1. You find the smallest n in that way that

1+2+...+n >= s (where s is the input)

For this you have to solve the equation in n:
n^2 + n 0 2s = 0
=> n= ceil( (sqrt(1+8s) -1)/2 )

2. Now your solution is n or n+1 or n+2, because
d=s-n*(n+1)/2 must be (even or odd I don't know very well english so I'm always in doubt wich is the word but ) d mod 2=0...

Good luck,

Carmen