ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1068. Sum

vilikan Why wrong (c) [5] // Problem 1068. Sum 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));
    }


}
Anatoliy V Tomilov Re: Why wrong (c) // Problem 1068. Sum 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.
Anatoliy V Tomilov Re: Why wrong (c) [3] // Problem 1068. Sum 2 Mar 2018 23:12
Also minus() is wrong.
vilikan Re: Why wrong (c) // Problem 1068. Sum 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
vilikan Re: Why wrong (c) // Problem 1068. Sum 3 Mar 2018 09:51


Edited by author 03.03.2018 09:54
vilikan No subject // Problem 1068. Sum 3 Mar 2018 09:52


Edited by author 03.03.2018 09:53