### A kind of math game

there are number 1,2,3....2013 on a blackboard,erase any two number a,b of them and input 2(a+b) in it.
assume the last number is c, find the biggest value of c%1000;

at first, i thought if 2013+2012, 2011+2(2012+2013)...so on is the biggest operation.
my code :
 ``123456789101112131415161718192021222324252627282930`` ``````#include #include #include using namespace std; int main(int argc, char **argv[]) { stackistack; int i,a,b,r; for(i=1;i<=2013;i++)//default stack; { istack.push(i); } if(istack.size()>1) { a=istack.top(); istack.pop(); b=istack.top(); istack.pop(); istack.push(2*(a+b)); //execute the process,erase two element and then push one element in to the stack; } r=istack.top()%1000; cout<

but i think this is wrong. 50 is too small.
what kind of code should I build?
Last edited on
The biggest possible value of `c%1000` is 999, but since c is an even number, the correct answer should be 998.

I don't understand the question: "`there are number 1,2,3....2013 on a blackboard,erase any two number a,b of them and input 2(a+b) in it.`", is that just a single operation, or is that to be repeated?

My interpretation is it is just a single operation - in which case nested for-loops for a and b should do.

it should be repeated and therefore there are many possible value of the last number.
Topic archived. No new replies allowed.