只要单纯的判断一下前后的乘积就好了, 因为不是很想处理倍数的关系, 所以我这里是用 string去处理。
代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define LL long long 4 #define ULL unsigned LL 5 #define fi first 6 #define se second 7 #define lson l,m,rt<<1 8 #define rson m+1,r,rt<<1|1 9 #define max3(a,b,c) max(a,max(b,c)) 10 const int INF = 0x3f3f3f3f; 11 const LL mod = 1e9+7; 12 typedef pair<int,int> pll; 13 char str[10]; 14 int n, k; 15 bool add(){ 16 for(int i = n - 1; i >= 1; i--){ 17 if((str[i-1]-'0')*(str[i]-'0'+1) <= k && str[i]-'0'+1 <= k) {str[i] = str[i] + 1;return true;} 18 else str[i] = '0'; 19 } 20 if(str[0]-'0'+1 <= k) {str[0] = str[0]+1; return true;} 21 return false; 22 } 23 int main(){ 24 scanf("%d%d",&n,&k); 25 str[0] = '1'; 26 for(int i = 1; i < n; i++) str[i] = '0'; 27 str[n] = '