Page 1 of 1

11614

Posted: Tue Jul 17, 2012 6:12 am
by crazy
it gave me wrong answer ...

Code: Select all

#include<stdio.h>
#include<math.h>
int main()
{
long int x,n,m,k,i;
scanf("%ld",&k);
for(i=0;i<k;i++)
{
    scanf("%ld",&n);
{
    m=(1+8*n)-1;
    x=sqrt(m)/2;
printf("%ld\n",x);
}}
return 0;
}

Re: 11614

Posted: Wed Jul 18, 2012 12:10 am
by brianfry713
Doesn't match the sample I/O.

11614 - Etruscan Warriors Never Play Chess

Posted: Thu Sep 20, 2012 8:10 pm
by tarsun
Why gave time limit exceed??

#include<stdio.h>

int main()
{
long int n,i,sum,f,x,test,t1;
scanf("%ld",&test);
for(t1=1;t1<=test;t1++)
{ sum=0;
scanf("%ld",&n);
for(i=1;;i++)
{
sum=sum+i;
if(sum==n)
{
printf("%ld",i);
break;
}
if(sum>n)
{
x=i-1;
printf("%ld",x);
break;
}

}
}
return 0;

}

Re: 11614

Posted: Thu Sep 20, 2012 9:09 pm
by brianfry713
Input:

Code: Select all

1
100000000000000
AC output:

Code: Select all

14142135

Re: 11614

Posted: Sat Sep 22, 2012 6:06 pm
by tarsun
is it correct code?
which datatype used for this program?

Re: 11614

Posted: Sun Sep 23, 2012 5:39 pm
by helloneo
I used 'unsigned long long'

Re: 11614

Posted: Thu Sep 19, 2013 9:13 pm
by raj

Code: Select all

Accepted
and Thanks Brianfry:)

Re: 11614

Posted: Thu Sep 19, 2013 9:36 pm
by brianfry713
There is a formula, I didn't precompute anything.

Re: 11614

Posted: Fri Sep 20, 2013 5:48 pm
by raj

Code: Select all

removed

Re: 11614

Posted: Fri Sep 20, 2013 9:30 pm
by brianfry713
Don't double post.

Re: 11614 - Etruscan Warriors Never Play Chess

Posted: Mon Dec 08, 2014 6:03 pm
by ssavi
Why It is getting TLE ?? Is there any correction ???

Code: Select all

#include<stdio.h>
int main()
{
    long long int n, i, t, sum;
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld",&n);
        sum=0; i=1;
        while(sum<n)
        {
            sum=sum+i;
            i++;
        }
        if(n<sum)
           {printf("%lld\n",i-2);}
        else if(n==sum)
            printf("%lld\n",i-1);
    }
    return 0;
}

Re: 11614 - Etruscan Warriors Never Play Chess

Posted: Mon Dec 08, 2014 10:31 pm
by brianfry713
You can solve each test case in constant time.

Re: 11614 - Etruscan Warriors Never Play Chess

Posted: Tue Dec 09, 2014 5:22 am
by ssavi
brianfry713 wrote:You can solve each test case in constant time.
I dont get your words .

Re: 11614 - Etruscan Warriors Never Play Chess

Posted: Wed Dec 10, 2014 1:25 am
by brianfry713
Your algorithm is too slow, it runs in O(n) for each test case. To solve it within the time limit, you can use a O(1) formula.