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 1117. Hierarchy

WA 5
Posted by Giorgi Saghinadze (Tbilisi SU) 15 Aug 2008 17:45
why WA 5, my program works at all tests on the board, please help me, admin give me this test if you can :(

#include <iostream>

using namespace std;

long long j,p[100],n,m,i,n2[100],k;

long long ans(long long n)
{
     if (n <= 1) return 0;
     i = 31;
     while (n2[i] > n)
     i = i - 1;


     if (n2[i] == n) return p[i] + ans(n - (1<<i)) ; else
     return p[i] + (i-1) + ans(n - (1<<i));
}

int main()
{
    p[0] = 0;
    p[1] = 0;
    n2[0] = 1;
    n2[1] = 2;
    for (i = 2; i <= 32; i++)
    {
        n2[i] = n2[i-1]*2;
        p[i] = p[i-1]*2 + (i-1);
    }


    cin>>n>>m;
    long long anss = ans(n) - ans(m);
        if (anss < 0) anss *= -1;
        cout<<anss<<endl;


    return 0;
}