Amount of Degrees[ural 1057]
http://acm.timus.ru/problem.aspx?space=1&num=1057
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
const int MM = 22222; int64 L, R, K, B, len; int64 C[33][33]; int64 p[111]; void get_p() { int64 i,j,k; p[0]=1; len=(int64)((log(1.0*R)/log(1.0*B))+1.0); // printf("%d\n",len); for(i=1;i<=len;i++) p[i]=p[i-1]*B; // for(i=0;i<=len;i++) printf("%d ",p[i]); printf("\n"); } void get_com() { int64 i,j,k; C[0][0]=1; for(i=1;i<32;i++) { C[i][0]=C[i-1][0]; for(j=1;j<=i;j++) C[i][j]=C[i-1][j]+C[i-1][j-1]; } } int64 calc(int64 x) { int64 i,j,k, sum=0, ans=0; for(i=len;i>=0;i--) { if(p[i]>x) continue; x-=p[i]; ans+=C[i][K-sum]; // printf("%d %d %d %d\n",i, x, p[i], ans); sum++; if(sum>K) break; } return ans; } void solve() { int64 i,j,k,ans=0; get_p(); ans=calc(R+1)-calc(L-1); // printf("%d\n",calc(15)); printf("%lld\n",ans); }