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

About Sum Problem1068
Posted by Saud 9 Nov 2011 21:42
Sir Kindly Tell me the why my this Problem's solution is not acceptable?
#include<iostream>
using namespace std;
int main()
{

    int num,n;
    int i;
    cin>>n;
    while(n>0)
    {
        cin>>num;
        if(num>10000)
            return 0;
        else if(num<0)
        {
            i = ((num*(num-1))/2)*(-1);
            cout<<i+1<<endl;
        }
        else
        cout<<(num*(num+1))/2<<endl;
        n--;
    }
    return 0;
}
Re: About Sum Problem1068
Posted by morbidel 9 Nov 2011 21:48
You have to read/write a single number.
Re: About Sum Problem1068
Posted by Saud 9 Nov 2011 21:59
But Sir when i was taking a single input then at that time also not accept my solution.
The error was "wrong answer Test#2".
Kindly tell me what was wrong that time?
Re: About Sum Problem1068
Posted by morbidel 9 Nov 2011 22:56
Well, obviously you have an incorrect formula
Did you made a check on the paper with, let's say N = -1?
The "i = ((num*(num-1))/2)*(-1); cout<<i+1<<endl;" formula is wrong also for the sample input, you will output 7.
Re: About Sum Problem1068
Posted by Saud 10 Nov 2011 14:44
No sir when i give input N=-1 the OutPut is 0.
If this is Wrong then tell me plz what should be output when N=-1
Re: About Sum Problem1068
Posted by morbidel 10 Nov 2011 16:18
How about for N = 0?
Re: About Sum Problem1068
Posted by Saud 10 Nov 2011 16:56
Thank you very much sir.
My solution was not able to generate required result when N = 0
Now after the correction in my Solution my solution is accepted.
Again Thank you for help me.