Count It

QUESTION

Foo was not amongst the most brilliant students of his class. So, he has some pending exams to clear. As the exams are approaching, this time he vowed to pass in all of them. This will only happen if he is not under stress. Foo’s stress can be calculated using a simple function called Foo_function which depends upon the time for which Foo studies continuously .\n\nFoo_funtion is defined as follows:\n\nF(t)=A(t^3)+B(t^2)+C*(t)+D, F(t)<=10^18\n\nwhere A,B,C,D belong to the set of prime numbers. t is the time in minutes for which foo studies continuously.\n\nAs foo is not very good at solving cubic equations, he seeks your help to find out the maximum number of minutes for which he can study continuously without taking stress. Help him find t such that F(t+1) > K, and F(t) <= K, where K is the maximum stress Foo can bear.\n\nInput:\n\nEach test case consists of a single line containing 5 space seperated positive numbers a, b, c, d, K.\n\nOutput:\n\nFor each test case, output a single integer t denoting the maximum time for which foo can study continuously without taking stress.

“TESTCASE_1”: “2 2 2 2 10\n###—###SEPERATOR—###—\n1”, “TESTCASE_2”: “2 3 5 7 1000\n###—###SEPERATOR—###—\n7”, “TESTCASE_3”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_4”: “0\n###—###SEPERATOR—###—\n0”, “TESTCASE_5”: “0\n###—###SEPERATOR—###—\n0

ANSWER

#include <stdio.h>
 
int main(){
	long int a,b,c,d,f,k;
  int t;
	
    {
        scanf("%ld", &a);
        scanf("%ld", &b);
        scanf("%ld", &c);
        scanf("%ld", &d);
        scanf("%ld", &k);
        for(t = 0; ; t++)
        {
            f = (a*t*t*t) + (b*t*t) + (c*t) + d;
            if(f > k)
            {
                if(t > 0)
                {
                    printf("%d\n", t-1);
                    break;
                }
                else
                {
                    printf("%d\n", t);
                    break;
                }
            }
                    }
    }
   return 0; 
}

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
CHP Adblock Detector Plugin | Codehelppro