P1988 火炬 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
搜索 枚举01串
#include <bits/stdc++.h>
#include <iostream>
#include<unordered_map>
#define x first
#define y second
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long LL ;
typedef unsigned long long ULL ;
typedef pair<int,int> PII ;
typedef pair<LL,int> PLI ;
const int N = 1e6 + 10 ,M=1000 + 10;
const LL INF2 = 1e17;
LL n,tot,a[N];
void dfs(LL x )
{
a[++ tot ] = x;
if(x > 1e18) return;
//构造一个01串
for(int i=0;i<=1;i ++ )//下一位数是0还是1
dfs(x * 10 + i);
}
inline void solve()
{
cin >> n;
dfs(1);// 最高位必须是1
sort(a+1,a+tot+1);
for(int i=1;i<=tot; i++)
if(a[i] % n == 0 )
{
cout << a[i]/n;
return;
}
cout <<"No Solution\n";
}
signed main()
{
ios
int T=1;
// cin>>T;
while(T -- )
{
solve();
}
return 0;
}