|
|
back to boardCommon Boardwhere is my solution to 1117 wrong? 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)); } |
|
|