Real Mangoes for Ranjith
Link to the question : MANGOES
HINT :
The question might look lengthy and you may think implementing the algorithm will be a tough task, but a little careful observation may make this question look very simple. As per the question mangoes are real if GCD of each pair of the set {mi, mi+1, mi+2} equals 1. Now this is only possible when mi and (mi + 2) are odd else if they are even, they will have at least 2 as their GCD. Hence all you need to is find the sum of the odd terms.
SOURCE CODE :
#include<stdio.h>
int main()
{
int t;
long long int n,x,s;
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
x=n;
if(n%2==0)
n=(n-2)/2;
else
n=(n-1)/2;
s=(n*n)%x;
printf("%lld\n",s);
}
return 0;
}
No comments:
Post a Comment