Here is my code this should output (8477559501395327) but it is giving(2084842641) whats the problem here. I tried long instead of int but it gives some different answer
int counter = 0;
int counter2 =0;
int k=203903;
int result=0;
int countequalk =0;
int i=0;
while(true){
if( i % 2 != 0){
counter++;
if(counter<k){
counter2=counter2+counter;
}
//System.out.println(counter+" "+i);
if(counter>counter2&&counter<=counter2+k){
result = result+i;
countequalk++;
}
if(countequalk==k){
break;
}
}
i++;
}
System.out.println(result);