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 1120. Sum of Sequential Numbers

Grigor Gevorgian What is the output for N=1 ? [13] // Problem 1120. Sum of Sequential Numbers 21 May 2008 22:14
Answer is 1 1
Grigor Gevorgian Re: What is the output for N=1 ? [11] // Problem 1120. Sum of Sequential Numbers 23 May 2008 17:21
But if A=1,P=1
A+P-1=1,
so A+(A+P-1)=2 NOT 1?Am I wrong?
The sequence is an arithmetic progression upto p terms.
So, when n=1, only 1 term is required ie p=1.
Hope you could understand.
Grigor Gevorgian Re: What is the output for N=1 ? [9] // Problem 1120. Sum of Sequential Numbers 23 May 2008 20:52
This is my code. It gets WA#7,but I cant find my mistake.Could you help,pls?

#include<iostream.h>
int main()
{
    int n,i,j,s;
    cin>>n;
    if(n==1)
    {
        cout<<"1 1";
        return 0;
    }

    if(n==2)
    {
        cout<<"2 1";
        return 0;
    }
    for(i=1;i<=n/2;i++)
    {
        s=i;
        for(j=i+1;s<n;j++)
            s+=j;
        if(s==n)
        {
            cout<<i<<" "<<j-i;
            return 0;
        }
    }
    cout<<n/2<<" "<<1;
    return 0;
}
rohit No subject [8] // Problem 1120. Sum of Sequential Numbers 25 May 2008 01:53
Maximum value of a is n not n/2.
Your program gives wrong answer for n=4.
Your output is 2 1 while correct one is 4 1.
SuperLight Re: No subject // Problem 1120. Sum of Sequential Numbers 25 May 2008 10:20
Grigor Gevorgian TLE #9 [5] // Problem 1120. Sum of Sequential Numbers 26 May 2008 01:27
Thanks a lot,I passed WA,but now TLE #9.This algo is too slow :(
rohit Re: TLE #9 // Problem 1120. Sum of Sequential Numbers 26 May 2008 03:37
Solve it mathematically.
indra Re: TLE #9 [3] // Problem 1120. Sum of Sequential Numbers 31 May 2008 23:35
try to manipulate this :

N = P*(2A + (P-1))/2

N = input
A & P = output

loop P to find A
Grigor Gevorgian OK, AC now. Thanks . [2] // Problem 1120. Sum of Sequential Numbers 13 Jun 2008 18:25
Aram Taranyan (YSU) Re: OK, AC now. Thanks . [1] // Problem 1120. Sum of Sequential Numbers 23 Apr 2009 20:48
Right answer for 1 is 0 2 not 1 0 !!!
Gevorgyan Aram Re: OK, AC now. Thanks . // Problem 1120. Sum of Sequential Numbers 23 Apr 2009 21:42
right answer is 1 1 ,
because 1=1+(1-1)
Nafis Sadique Re: No subject // Problem 1120. Sum of Sequential Numbers 14 Aug 2010 06:24
ok i think this should be 2 2
rohit wrote 25 May 2008 01:53
Maximum value of a is n not n/2.
Your program gives wrong answer for n=4.
Your output is 2 1 while correct one is 4 1.