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

shengxi4 why i got wrong 4? [3] // Problem 1120. Sum of Sequential Numbers 23 Jul 2004 21:54
#include<stdio.h>

long n,a,k;
void work ()
{
   long i,na,x;
   if (n<316227) x=2*n; else x=316227;
    for (i=x;i>=1;i--)
     {
       na=2*n+i-i*i;
       if (((na%(2*i))==0)&&(na>0))
     {
        na=na/(2*i);
        a=na;
        k=i;
        break;
     }
    }
}
int main ()
{
  scanf ("%ld",&n);
  work ();
  printf ("%ld %ld",a,k);
   return 0;
}
Kopeliovitch Sergey (1) Re: why i got wrong 4? [1] // Problem 1120. Sum of Sequential Numbers 24 Jul 2004 20:14
Test: 10^9
Your program result: 4811 148480
My AC program result: 26263 25600
plague Re: why i got wrong 4? // Problem 1120. Sum of Sequential Numbers 27 Dec 2007 22:10
My program result: 1243 640
for n= 10^6



Edited by author 27.12.2007 22:11
Орифжон Наркулов Re: why i got wrong 4? // Problem 1120. Sum of Sequential Numbers 25 Mar 2007 12:39
#include<iostream>
#include<stdio.h>
using namespace std;
__int64 n,a,k;
void work ()
{
__int64 i,na,x;
if (n<316227) x=2*n; else x=316227;
for (i=x;i>=1;i--)
{
na=2*n+i-i*i;
if (((na%(2*i))==0)&&(na>0))
{
na=na/(2*i);
a=na;
k=i;
break;
}
}
}
int main ()
{
cin>>n;
work ();
cout<<a<<" "<<k;
return 0;
}
shengxi4 wrote 23 July 2004 21:54
#include<stdio.h>

long n,a,k;
void work ()
{
   long i,na,x;
   if (n<316227) x=2*n; else x=316227;
    for (i=x;i>=1;i--)
     {
       na=2*n+i-i*i;
       if (((na%(2*i))==0)&&(na>0))
     {
        na=na/(2*i);
        a=na;
        k=i;
        break;
     }
    }
}
int main ()
{
  scanf ("%ld",&n);
  work ();
  printf ("%ld %ld",a,k);
   return 0;
}