Click Here to see the problem detail.
Solution
multiply n by 567,then divide the result by 9 =n*567/9=n*63. Now a question may arise why this simplification is needed? Ans: If n*567/9 is written then n*567 will be evaluated then this result will be divided by 9. but n*567 will produce a large value when the value of n is large. This large value will cause overflow error or give wrong output.
Source Code
#include<stdio.h>
int main()
{
int testCase;
int n;
scanf("%d",&testCase);
while(testCase--)
{
scanf("%d",&n);
n=(n*63+7492)*5-498;
if(n<0)
n=-n;
n=n/10;
printf("%d\n",n%10);
}
return 0;
}
Next Previous