ll mul( ll a , ll b , ll md ){ return ( a * b - (ll)( (longdouble)a / md * b + 0.5 ) * md + md ) % md; } ll Pow( ll x , ll a , ll md ){ ll cur = x % md , ans = 1; while( a ) { if( a & 1 ) ans = mul( ans , cur , md ); cur = mul( cur , cur , md ) , a >>= 1; } return ans; }
constint ck[] = {2,3,5,7,11,13,17,19,23} , _l = 8; boolmiller( ll n ){ if( n == 1 ) returnfalse; ll t = n - 1; int cn = 0; while( !( t & 1 ) ) t >>= 1 , ++ cn; for( int i = 0 ; i < _l ; ++ i ) { if( n == ck[i] ) returntrue; ll a = Pow( ck[i] , t , n ) , nex = a; for( int j = 1 ; j <= cn ; ++ j ) { nex = mul( a , a , n ); if( nex == 1 && a != 1 && a != n - 1 ) returnfalse; a = nex; } if( a != 1 ) returnfalse; } returntrue; }
inline ll f( ll x , ll c , ll md ){ return ( mul( x , x , md ) + c ) % md; }
inline ll _rand( ) { return (ll) rand() << 32 | rand(); } inline ll _randw() { return (ll)rand() << 48 | (ll)rand() << 32 | rand() << 16 | rand(); } inline ll _abs( ll x ) { return x > 0 ? x : -x; } inline ll gcd( ll a , ll b ){ return !b ? a : gcd( b , a % b ); }
inline ll pollard_rho( ll n ){ ll s = 0 , t = 0 , c = _rand() % ( n - 1 ) + 1 , val = 1; for( int cir = 1 ; ; cir <<= 1 , s = t , val = 1 ) { for( int i = 0 ; i < cir ; ++ i ) { t = f( t , c , n ) , val = mul( val , _abs( t - s ) , n ); if( i % 127 == 0 ) { ll g = gcd( val , n ); if( g != 1 ) return g; } } ll g = gcd( val , n ); if( g != 1 ) return g; } }
vector<ll> divs; inlinevoidanalyze( ll n ){ if( n == 1 ) return; if( miller( n ) ) { divs.push_back( n ); return; } ll d = n; while( d == n ) d = pollard_rho( n ); n /= d; analyze( n ) , analyze( d ); }