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

Why TLE # 9?????? The code is very simple!
Posted by Black Raven 30 Mar 2005 20:08
Please check my code:

#include <iostream>
#include <cmath>
using namespace std;
double y(double x, double z){
    double h =( 1 - 2*x + sqrt(4*x*x-4*x+1+8*z) )/2;
    if(h-floor(h) == 0)
    return h;
    else return -1;
    }

int main(){
    unsigned z;
    cin>>z;
    for(unsigned x=1; x<=z; x++)
    if(y(x, z)!=-1){
    cout<<x<<" "<<y(x, z);
    break;
    }
    return 0;
    }
Re: Why TLE # 9?????? The code is very simple!
Posted by Burunduk1 31 Mar 2005 01:11
I think you have TLE because of

for(unsigned x=1; x<=z; x++)

Where Z can be about 10^9...
Are you sure it will finish some day?
Re: Why TLE # 9?????? The code is very simple!
Posted by Black Raven 31 Mar 2005 12:04
It works rather fast. When z == 1000000000 we have "26263 25600". And what are your variants to make this program faster?
Re: Why TLE # 9?????? The code is very simple!
Posted by Burunduk1 1 Apr 2005 03:19
1) Bad (for your solution) test: 12224444
   (run time is about 2 sec)
2) Hint: N >= P(P-1)/2 => P is not more than 50000