Wednesday 22 July 2015

CUTCAKE


Eat all the brownies !

Link to the question : CUTCAKE 

HINT :

A good mathematical question. You can  approach to the solution of the question by thinking it this way - how will n lines cut a plane so that you get maximum pieces. Many of you might have solved this question during your entrance exam preparation. If not here's the solution:
1 line divides a plane into 2 parts.
2 lines divide it into 4 and similarly 3 lines divide it into 7.
If you go further, you will see that the differences of these numbers are in AP. Hence, derive the formula and solve it accordingly.

RECOMMENDED QUESTION :

You will love solving this adhoc question . 

SOURCE CODE :

#include<stdio.h>

#include<math.h>

int main()

{

      long long int n,tn;

      int t;

      scanf("%d",&t);

      while(t--)

      {

          scanf("%lld",&tn);

          if(tn==1)

            printf("0\n");



          else  {

          n= (1 + sqrt(1+ 8*(tn-1)));

          n=n/2;

          printf("%lld\n",n-1);

      } }

      return 0;



}

    

No comments:

Post a Comment