Untitled
user_0483151
plain_text
a month ago
633 B
0
Indexable
Never
//_za*mita_ #include <bits/stdc++.h> using namespace std; int a[105], cnt = 0; int main (){ int d, k; while (cin >> d >> k){ string res=""; if (k == 1){ cout << d << endl; continue; } int i = 1, q; a[1] = d; bool check = false; while (check == false){ res = char(a[i]+'0') + res; q = a[i]*k + cnt; i++; a[i] = q%10; cnt = q/10; if (a[i] == d && cnt == 0) check = true; } if (a[i-1] == 0) cout << -1 << "\n"; else cout << res <<"\n"; } }
Leave a Comment