### Statement

Create a code to determine the amount of integers, lying in the set [X;Y] and being a sum of exactly K different integer degrees of B.
Example. Let X=15, Y=20, K=2, B=2. By this example 3 numbers are the sum of exactly two integer degrees of number 2:
$17 = 2^4+2^0$,
$18 = 2^4+2^1$,
$20 = 2^4+2^2$.

#### Input

The first line of input contains integers X and Y, separated with a space $(1 ≤ X ≤ Y ≤ 2^{31}−1)$. The next two lines contain integers K and B $(1 ≤ K ≤ 20; 2 ≤ B ≤ 10)$.

#### Output

Output should contain a single integer — the amount of integers, lying between X and Y, being a sum of exactly K different integer degrees of B.

### 代码

#include
using namespace std;
int k,b,f[50][50];
void init(){
f[0][0]=1;
for (int i=1;i<50;i++){
f[i][0]=f[i-1][0];
for (int j=1;j<=i;j++){
f[i][j]=f[i-1][j]+f[i-1][j-1];
}
}
}
int solve(int l){
vectorv;
while(l){
v.push_back(l%b);
l/=b;
}
int cnt=0,ans=0;
for (int i=v.size()-1;~i;i--){
if (v[i]==1){
ans+=f[i][k-cnt];
cnt++;
if (cnt==k) break;
}
if (v[i]>1){
ans+=f[i+1][k-cnt];
break;
}
}
if (cnt==k) ans++;
return ans;
}
int main(){
ios::sync_with_stdio(false);
init();int x,y;
cin>>x>>y>>k>>b;
cout<
 
 Share Show Comments 【计蒜客 NOIP 提高组模拟竞赛第二试】手拉手 / 题解 原题地址 题目描述 小 P 是个幼儿园老师。有一天，他组织 n 个小朋友玩游戏。游戏开始时，每个小朋友伸出两只手，没有手相互拉在一起。… 18 Sep 2018 【随想】宿醉后遗忘 写这篇文章的想法在我脑海中盘旋已久。它最后的样子和我设想的有很大不同，实属水平有限，请读者谅解。 零坦率地讲，我是一个喜欢喝酒的人。尽管每个合法在大陆境内销售的酒类品牌都会在自家的产品上写未成年人禁止饮酒，但是除了淘宝，并没有任何阻力使我接触不到这种畅销的饮料。虽然在精神病学里有专门的一节讲酒精导致的精神障碍，政府的宣传也不太欢迎国民饮酒，但少有中国人远离酒精。… 06 Sep 2018 
 
 
 Topics Thought: 30 Study: 26 Selected: 26 Zepto's © 2022 Sponsor Data & privacy Contact → Published with Ghost • Theme Attila • System theme 
 $(document).ready(function () { var viewport =$(window); var post = $('.post-content'); // Responsive videos with fitVids post.fitVids(); // Format code blocks and add line numbers function codestyling() {$('pre code').each(function(i, e) { // Code highlight hljs.highlightBlock(e); // No lines for plain text blocks if (!$(this).hasClass('language-text')) { var code =$(this); // Calculate amount of lines var lines = code.html().split(/\n(?!$)/g).length; var numbers = []; if (lines > 1) { lines++; } for (i = 1; i < lines; i++) { numbers += '<span class="line" aria-hidden="true">' + i + '</span>'; } code.parent().append('<div class="lines">' + numbers + '</div>'); } }); } codestyling(); // Reading progress bar on window top function readingProgress() { var postBottom = post.offset().top + post.height(); var viewportHeight = viewport.height(); var progress = 100 - (((postBottom - (viewport.scrollTop() + viewportHeight) + viewportHeight / 3) / (postBottom - viewportHeight + viewportHeight / 3)) * 100);$('.progress-bar').css('width', progress + '%'); (progress > 100) ? $('.progress-container').addClass('complete'):$('.progress-container').removeClass('complete'); } readingProgress(); // Trigger reading progress viewport.on({ 'scroll': function() { readingProgress(); }, 'resize': function() { readingProgress(); }, 'orientationchange': function() { readingProgress(); } }); // Check if disqus is defined by code injection if (typeof disqus === 'undefined') { // hide comment section $('.post-comments').css({ 'display': 'none' }); } else {$('#show-disqus').on('click', function() { $.ajax({ type: "GET", url: "//" + disqus + ".disqus.com/embed.js", dataType: "script", cache: true });$(this).parent().addClass('activated'); }); } });