#include using namespace std; typedef long long ll; typedef unsigned long long L; typedef pair P; #define REP(i,n) for(ll i=0;i> N >> B; L A=N%B; A=(ll)A; B=(ll)B; if(gcd(N,B)!=1){ cout << "NaN" << endl; return 0; } ll x,y; ll g=f(A,B,x,y); cout << (B+mod_inverse(A,B))%B << endl; return 0; }