题目链接:https://www.luogu.com.cn/problem/P1112
思路:
如果暴力跑肯定不行,不妨想一下这些数字的特点。
首先肯定是某个进制下的波浪数,所以枚举每位的0~p-1(p进制),然后统计出所有l,r范围内的波浪数,次数+1.
最后只要输出l,r范围内所有波浪数被标记的次数等于t的数字就好了。
代码:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7+10;
int tim[N] = {0};
int main(void)
{
int x,y,l,r,t;
scanf("%d%d%d%d%d",&x,&y,&l,&r,&t);
for(int p=x;p<=y;p++)
{
for(int i=1;i<p;i++)
{
for(int j=0;j<p;j++)
if(i!=j){
int tp = 0,cnt = 0;
while(tp <= r)
{
if(cnt%2==0) tp = tp*p + i;
else tp = tp*p + j;
cnt++;
if(l <= tp && tp <= r) tim[tp]++;
}
}
}
}
for(int i=l;i<=r;i++)
if(tim[i] == t) printf("%d\n",i);
return 0;
}