Wrong answer for simple program

I am new to codechef i am trying a very simple program however i get wrong answer everytime i run it on IDE it prints the correct output. Can someone point out where is the mistake? I am trying this problem http://www.codechef.com/CDOT2015/problems/CDOUT2/

#include <stdio.h>
int main(void)
{
int t;
long long int n,k,c;
scanf("%d",&t);

while(t--)
{
scanf("%lld %lld",&n,&k);

if(n==k)
    c=((n+k)+(n*k));
else
{
c=n*k*2;
}
printf("%lld \n",c);

}

return 0;

}

It is reasonable that your code outputs wrong answers.
here is a simple test case explained

3855*5=19275 if done in right way

3855*5=19110 if done in wrong way

adding these two results [38385],which is indeed the answer and your code fails to produce the same.
I believe the problem is not that simple after all ,I think(from your code) you are considering the case when N,k are single digit integers. try working on that.N,k may assume higher values too, btw i am also new to codechef, happy coding :slight_smile:

ok i get it but how come 19110?

You have considered that input number N is always a single digit number which is incorrect. The procedure of multiplication here is not a single step process. It is digit by digit multiplication. You have to multiply each digit of N by K. If any digit of N is equal to K then you have to add them. It will require a loop to find the wrong answer for each test case.

3855 * 5 = (5+5) * 1 + (5+5) * 10 + (8 * 5) * 100 + (3 * 5) * 1000 = 19110 for wrong answer.

12 * 2 = (2+2) * 1 + (1 * 2) * 10 = 24 for wrong answer

Hope it helps!

//