| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
G++AC C++WA 代码很短 数论组合排列#include <stdio.h>
int C[32][32]={{0}};
void Init()
{
int i,j;
C[0][0]=1;
for(i=1; i<33; i++){
C[i][0]=1;
for(j=1; j<=i; j++){
C[i][j]=C[i-1][j-1]+C[i-1][j];
}
}
}
int count(int n)
{
if(n<=1)return 0;
int i,j,L=0,zer=0,one=1,res=0;
bool d[32]={0};
while(n){
d[L]=n&1;
n>>=1,L++;
}
for(i=2;i<=L-1;i++)for(j=(i+1)>>1;j<=i-1;j++)
res+=C[i-1][j];
for(i=L-1;i>=1;i--){
if(d[i-1]){
for(j=i-1;i-1-j+one<=j+zer+1;j--)
res+=C[i-1][j];
one++;
}else{
zer++;
}
}
return res+(zer>=one);
}
int main()
{
int s,f;
Init();
while(~scanf("%d%d",&s,&f)){
printf("%d\n",count(f)-count(s-1));
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator