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

Common Board

where is my solution to 1117 wrong?
Posted by Liviu Lalescu 6 Oct 2001 19:01
Please can you tell me where does my program output wrong
answer?

#include <string.h>
#include <assert.h>
#include <fstream.h>
#include <stdio.h>

//ifstream in("hier.in");
#define in cin

double dist(unsigned long x,unsigned long y){
    unsigned long a[32+1],b[32+1];
    int i;
    b[0]=0;
    for(i=1;i<32;i++)
        b[i]=y/(1L<<i)-(x-1)/(1L<<i)-b[i];
    double q=0;
    for(i=2;i<32;i++){
        a[i]=2 * b[i];
        if(y==(1L<<i))
            a[i]--;
        if(x==(1L<<i))
            a[i]--;
               q+=(i-1)*a[i];
    }
    return q;
}

void main(){
    unsigned long x,y,tmp;
    in>>x>>y;
    if(x>y)
        tmp=x,x=y,y=tmp;
        printf("%.0lf\n",dist(x,y));
}