从P2841过来的,复制一下代码,稍微改了一下,只得了60分。。。(迭代加深搜索)
这是代码↓
#include <stdio.h>
#define int __int128
int STEP = 1;
int n,len;
bool flag = true;
static inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;
}
static inline void write(int x){
if(x<0)putchar('-'),x=-x;
if(x>9)write(x/10);
putchar(x%10+'0');
return;
}
static inline bool IDDFS(int x,int y,int deep){
if(y%x == 0) return write(y/x),true;//,putchar(' '),write(y),true;
if(deep >= STEP) return false;
return (IDDFS(x,y*10+1,deep+1) || IDDFS(x,y*10,deep+1));
}
signed main(){
n = read();
while(!IDDFS(n,1,0)) STEP ++;
return 0;
}