Hello everyone,
Actually i am unable to understand a strange behavior of the code for the problem https://www.codechef.com/problems/COINS
if i submit this code, then it gives me WRONG ANSWER
#include<stdio.h>
#include<math.h>
int arr[500000]={0};
int t;
int func(int);
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
printf("%d\n",func(n));
}
}
int func(int a)
{
if(a<=500000)if(arr[a]!=0) return arr[a];
//if(a%12!=0) return a;
if((a/2)+(a/3)+(a/4) <=a) {/*if(a<=500000)arr[a]=a;*/return a;}
else {
t=func(a/2)+func(a/3)+func(a/4);
if(a<=500000) arr[a]=t;
return t;
}
}
But if i write printf("%u\n",func(n));
instead of printf("%d\n",func(n));
then it gives me Correct answer.
Whats the possible reason???