#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    string a;
    ll b;
    cin>>a>>b;
    ll res = 0;
    int n = a.size();
    for(int i=0;i<n;i++)
    {
        res = (res*10+a[i]-'0')%b;
    }
    ll ans = __gcd(res,b);
    cout<<ans<<'\n';

}

诈骗题,看似高精度,实则不然,我们只需要大数字取小数字模,然后直接求gcd即可,因为小数字的范围在1e9内