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

What is the output for N=1 ?
Posted by Grigor Gevorgian 21 May 2008 22:14
Re: What is the output for N=1 ?
Posted by rohit 23 May 2008 13:40
Answer is 1 1
Re: What is the output for N=1 ?
Posted by Grigor Gevorgian 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?
Re: What is the output for N=1 ?
Posted by rohit 23 May 2008 18:38
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.
Re: What is the output for N=1 ?
Posted by Grigor Gevorgian 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;
}
No subject
Posted by rohit 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.
Re: No subject
Posted by SuperLight 25 May 2008 10:20
TLE #9
Posted by Grigor Gevorgian 26 May 2008 01:27
Thanks a lot,I passed WA,but now TLE #9.This algo is too slow :(
Re: TLE #9
Posted by rohit 26 May 2008 03:37
Solve it mathematically.
Re: TLE #9
Posted by indra 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
OK, AC now. Thanks .
Posted by Grigor Gevorgian 13 Jun 2008 18:25
Re: OK, AC now. Thanks .
Posted by Aram Taranyan (YSU) 23 Apr 2009 20:48
Right answer for 1 is 0 2 not 1 0 !!!
Re: OK, AC now. Thanks .
Posted by Gevorgyan Aram 23 Apr 2009 21:42
right answer is 1 1 ,
because 1=1+(1-1)
Re: No subject
Posted by Nafis Sadique 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.