ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1068. Sum

Why wrong (c)
Posted by vilikan 2 Mar 2018 22:00
#include <stdio.h>
#include <math.h>

int plus(int number){
return number*(number+1)/2;
}
int minus(int number){
return (-(number*(number+1)/2))+number;
}
int main(){
int N;

scanf("%d",&N);
if(abs(N)>=1  && abs(N)<=10000){

if(N<0)
printf("%d",minus(N));
else
printf("%d",plus(N));
}

}
Re: Why wrong (c)
Posted by Orient 2 Mar 2018 23:10
Why do you think, that 0 is prohibited input?

What the reason to check input at all? "if(abs(N)>=1  && abs(N)<=10000)" is superfluous. The statement of the problem can't lie.
Re: Why wrong (c)
Posted by Orient 2 Mar 2018 23:12
Also minus() is wrong.
Re: Why wrong (c)
Posted by vilikan 3 Mar 2018 09:51
Thanks you so much. I'm new to olympiad programming and I sometimes make silly mistakes thanks to pointing to them
Re: Why wrong (c)
Posted by vilikan 3 Mar 2018 09:51

Edited by author 03.03.2018 09:54
No subject
Posted by vilikan 3 Mar 2018 09:52

Edited by author 03.03.2018 09:53