#include<bits/stdc++.h>
#include <unordered_map>
using namespace std;
template<class...Args>
void debug(Args... args) {//参数包Parameter pack
auto tmp = { (cout << args << ' ', 0)... };
cout << "\n";
}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>pll;
typedef pair<int, int>pii;
const ll N = 1e6 + 5;
const ll MOD = 1e9 + 7;
const ll INF = 0x7fffffff;
int dis[N];
void bfs(int n,int x) {
queue<int> q;
q.emplace(1 % n);
while(!q.empty()){
int u = q.front();q.pop();
int v;
v = u * 10 % n;
if (dis[v] > dis[u] + 1) {
dis[v] = dis[u] + 1;
q.emplace(v);
}
v = (u + x - 1) % n;
if (dis[v] > dis[u] + 1) {
dis[v] = dis[u] + 1;
q.emplace(v);
}
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, x;
cin >> n >> x;
memset(dis, 0x3f, sizeof dis);
dis[1 % n] = 0;
bfs(n, x);
cout << (dis[0] > 1e9 ? -1 : dis[0]);
return 0;
}
12-06
07-12
07-12
09-07
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交