I have a very long question and some part of the question, involves two functions named gp(a,t)
and fibo(a,t)
.
gp(a,t)
gets two integer numbers a ,t and must return the smallest prime number that is greater than or equal to (t/100)*a
fibo(a,t)
gets two integer numbers a,t and must return the biggest member of fibonacci series that is less than or equal to (t/100)*a
. (We consider 0 as the first member of fibonacci series in this problem, so it is 0 1 1 2 3 5 8 13 ...)
(The problem didn't mention that we must save that (t/100)*a
as float but according to its examples, it must be considered a float for example if it is 3.5 then gp
must return 5 and not 3.)
I implemented this functions but in some unknown test cases, it fails and so I want to know which part of my functions are wrong. Is there any a,t that my functions give wrong answer for them?
Note: I defined everything as long long because the main very long part of the question said to use long long because the numbers will get big.
Note 2: It doesn't give time limit error, so there is no problems like infinite loop or not optimised calculation of prime numbers.
My functions: (written in c)
long long int primeCheck(long long int a)
{
if (a==1 || a ==0)
{
return 0;
}
long long int isPrime = 1;
;
for (long long int i =2;i*i<=a;i++)
{
if (a%i==0)
{
isPrime=0;
break;
}
}
return isPrime;
}
long long int fibo (long long int a, long long int t)
{
float check = (t*1.00/100)*1.00*a;
if (check ==0)
{
return 0;
}
else if (check==1)
{
return 1;
}
long long int f_n_2 = 0;
long long int f_n_1 = 1;
long long int f_n=0;
while (f_n<=check)
{
f_n = f_n_2 + f_n_1;
f_n_2 = f_n_1;
f_n_1 = f_n;
if (f_n > check)
{
return f_n_2;
}
else if (f_n == check)
{
return f_n;
}
}
return 0;
}
long long int gp (long long int a , long long int t)
{
float check = (t*1.00/100)*1.00*a;
long long int i=ceil(check);
while(1)
{
if (primeCheck(i) )
{
return i;
}
i++;
}
return 0;
}
PS1. The problem is Solved. The issue was in the judge system and the code is just fine!