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 :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <cstdlib>
#include <iostream>
#include <stack>

using namespace std;

int main(int argc, char **argv[])
{
    stack<int>istack;
    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<<istack.top()<<endl;//the last one is on the top;     
cout<<"the mode value is equal to "<<r<<endl;   
    
    system("PAUSE");
    return EXIT_SUCCESS;
}

//output is 50; 

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.