ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1079. Maximum

why 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