Untitled
#include <bits/stdc++.h> #define maxn 100000 using namespace std; int d, k, a[maxn]; int main(){ while ( cin >> d >> k ) { if ( k == 1 ) cout << d << endl; else { int so = 0; int ktra = 0; int length = 1; a[1] = d; int recall = 0; for ( int i = 1; i <= 101; i++) { so = a[length] * k + recall; a[length + 1] = so % 10; recall = so/10; if ( recall == 0 && a[length + 1] == d && a[length] > 0 ) ktra = 1; if ( ktra == 1 ) { for ( int i = length; i >= 1; i--) cout << a[i]; cout << endl; break; } length = length + 1; } if ( ktra == 0 ) cout << -1 << endl; } } }
Leave a Comment