// 誤解法(exp(log/3))チェック #pragma GCC optimize ( "O3" ) #pragma GCC optimize( "unroll-loops" ) #pragma GCC target ( "sse4.2,fma,avx2,popcnt,lzcnt,bmi2" ) #include #include #include #include #include #include using namespace std; using ll = long long; #define MAIN main #define TYPE_OF( VAR ) remove_const::type >::type #define UNTIE ios_base::sync_with_stdio( false ); cin.tie( nullptr ) #define CEXPR( LL , BOUND , VALUE ) constexpr const LL BOUND = VALUE #define CIN( LL , A ) LL A; cin >> A #define ASSERT( A , MIN , MAX ) assert( ( MIN ) <= A && A <= ( MAX ) ) #define CIN_ASSERT( A , MIN , MAX ) CIN( TYPE_OF( MAX ) , A ); ASSERT( A , MIN , MAX ) #define FOR( VAR , INITIAL , FINAL_PLUS_ONE ) for( TYPE_OF( FINAL_PLUS_ONE ) VAR = INITIAL ; VAR < FINAL_PLUS_ONE ; VAR ++ ) #define REPEAT( HOW_MANY_TIMES ) FOR( VARIABLE_FOR_REPEAT ## HOW_MANY_TIMES , 0 , HOW_MANY_TIMES ) #define QUIT return 0 #define COUT( ANSWER ) cout << ( ANSWER ) << "\n" template class TwoByTwoMatrix { public: T m_M00; T m_M01; T m_M10; T m_M11; public: inline TwoByTwoMatrix( const T& M00 , const T& M01 , const T& M10 , const T& M11 ) noexcept; inline TwoByTwoMatrix& operator=( const TwoByTwoMatrix& mat ) noexcept; inline TwoByTwoMatrix& operator+=( const TwoByTwoMatrix& mat ); inline TwoByTwoMatrix& operator-=( const TwoByTwoMatrix& mat ); inline TwoByTwoMatrix operator*( const TwoByTwoMatrix& mat ); inline TwoByTwoMatrix operator/( const T& t ); }; template inline TwoByTwoMatrix::TwoByTwoMatrix( const T& M00 , const T& M01 , const T& M10 , const T& M11 ) noexcept : m_M00( M00 ) , m_M01( M01 ) , m_M10( M10 ) , m_M11( M11 ) {} template inline TwoByTwoMatrix& TwoByTwoMatrix::operator=( const TwoByTwoMatrix& mat ) noexcept { if( &mat != this ){ m_M00 = mat.m_M00; m_M01 = mat.m_M01; m_M10 = mat.m_M10; m_M11 = mat.m_M11; } return *this; } template inline TwoByTwoMatrix& TwoByTwoMatrix::operator+=( const TwoByTwoMatrix& mat ) { m_M00 += mat.m_M00; m_M01 += mat.m_M01; m_M10 += mat.m_M10; m_M11 += mat.m_M11; return *this; } template inline TwoByTwoMatrix& TwoByTwoMatrix::operator-=( const TwoByTwoMatrix& mat ) { m_M00 -= mat.m_M00; m_M01 -= mat.m_M01; m_M10 -= mat.m_M10; m_M11 -= mat.m_M11; return *this; } template inline TwoByTwoMatrix TwoByTwoMatrix::operator*( const TwoByTwoMatrix& mat ) { return TwoByTwoMatrix ( m_M00 * mat.m_M00 + m_M01 * mat.m_M10 , m_M00 * mat.m_M01 + m_M01 * mat.m_M11 , m_M10 * mat.m_M00 + m_M11 * mat.m_M10 , m_M10 * mat.m_M01 + m_M11 * mat.m_M11 ); } template inline TwoByTwoMatrix TwoByTwoMatrix::operator/( const T& t ) { return TwoByTwoMatrix ( m_M00 / t , m_M01 / t , m_M10 / t , m_M11 / t ); } // マクローリン展開の収束域から外れるので機能しない template inline TwoByTwoMatrix log( const TwoByTwoMatrix& mat ) { TwoByTwoMatrix answer{ 0 , 0 , 0 , 0 }; TwoByTwoMatrix power{ 1 , 0 , 0 , 1 }; TwoByTwoMatrix mat_shift{ mat.m_M00 - 1 , mat.m_M01 , mat.m_M10 , mat.m_M11 - 1 }; FOR( i , 1 , 15 ){ power = power * mat_shift; if( i % 2 == 0 ){ answer -= power / i; } else { answer += power / i; } } return answer; } template inline TwoByTwoMatrix exp( const TwoByTwoMatrix& mat ) { TwoByTwoMatrix answer{ 0 , 0 , 0 , 0 }; TwoByTwoMatrix div_power{ 1 , 0 , 0 , 1 }; FOR( i , 0 , 15 ){ answer += div_power; div_power = ( div_power * mat ) / ( i + 1 ); } return answer; } int MAIN() { UNTIE; CEXPR( int , bound_T , 100000 ); CIN_ASSERT( T , 1 , bound_T ); REPEAT( T ){ CIN( double , M00 ); CIN( double , M01 ); CIN( double , M10 ); CIN( double , M11 ); TwoByTwoMatrix M{ M00 , M01 , M10 , M11 }; TwoByTwoMatrix Mcbrt = exp( log( M ) / 3 ); cout << fixed << setprecision( 5 ); cout << Mcbrt.m_M00 << " " << Mcbrt.m_M01 << "\n"; cout << Mcbrt.m_M10 << " " << Mcbrt.m_M11 << "\n"; } QUIT; }