|
|
back to boardwhy my recursive solution is giving WA??? Posted by Suparna 24 Apr 2019 19:40 int main() { long int n,res; while(1){ scanf("%ld",&n); if(n!=0){ if(n%2==0){ res=function(n-1); printf("%ld\n",res); } else{ res=function(n); printf("%ld\n",res); } } else{ return 0; } } //gives right ans in codeblocks but here gives WA....Why?? return 0; } long int function(long int n){ if(n==1){ return 1; } if(n%2==0){ return 1; } else if(n%2==1){ return function(n/2)+function(n/2+1); } } Re: why my recursive solution is giving WA??? Posted by mission 11 Jun 2024 21:50 you have to print the maximux number of n range.but in recursive formula it alawys give the n th value . n th value and maximum value of n range is not same |
|
|