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

Wrong answer. Why?
Posted by Alexandr 17 Aug 2012 11:32
#include <stdio.h>
unsigned long get_an(unsigned long n);
int main(){
    unsigned long n[10],i;
    for(i=0; ; ++i){
        scanf("%ld", &n[i]);
        if(!n[i])
            break;
        n[i]=get_an(n[i]+n[i]%2-1);
    }
    for(i=0; n[i]; ++i)
        printf("%ld\n", n[i]);
    return 0;
}
unsigned long get_an(unsigned long n){
    if(n==1)
        return 1;
    if(n%2)
        return ( get_an((n-1)/2)+get_an((n-1)/2+1) );
    else
        return get_an(n/2);
}