Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
760 B
2
Indexable
Never
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
        long long n, x, maxm, temp, ans=0;
        cin>>n>>x;
        maxm = x, temp = n;
        while (maxm<=n) {
            maxm*=10;
            maxm+=x;
        }
        maxm/=10;
        while (temp>0 && maxm!=0) {
            if (temp>=maxm) {
                int q = temp/maxm;
                ans += q;
                temp = temp%maxm;
                maxm/=10;
            }
            else maxm/=10;
        }
        if (temp==0) cout << ans << endl;
        else cout << -1 << endl;

    }
}