题目描述:
签到题,找规律,
手推了规律如下:
AC代码:
/*
2017年8月29日22:33:28
Problem A. Arithmetic Derivative
AC 找规律+简单DFS+溢出处理
*/
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const ll inf=2e18;
//讲满足k=1的前6个数存下来 用来搜索
ll p[]={4,27,3125,823543,285311670611,302875106592253};
ll cur,k,r;//当前层数的值,需要搜索的层数,上界
ll ans[1000];
set<ll> st;//用set是因为题目要求排序+去重
set<ll>::iterator it;
void dfs(ll num,ll cur){
if(num==k){
for(int i=0;i<6;i++){
ll tmp=cur*p[i];
//这里是对溢出的处理
/*
如果不满足条件也就是说 p[i]*cur 会大于INF,那么数据会发生溢出
溢出的数据不满足条件,舍去
*/
if((inf/cur)>=p[i]){
/*不发生溢出再考虑与r的大小*/
if(tmp<=r) st.insert(tmp);
else return;
}
else return;
}
}
else if(num<k){
for(int i=0;i<6;i++){
if((inf/cur)>=p[i])
dfs(num+1,cur*p[i]);
else return;
}
}
}
int main(){
scanf("%lld%lld",&k,&r);
dfs(1,1);
printf("%lld\n",st.size());
for(it=st.begin();it!=st.end();it++){
if(it!=st.begin()) printf(" ");
printf("%lld",*it);
}printf("\n");
return 0;
}