/** * @file 2562.cpp * @brief yukicoder No.2562 数字探しゲーム(緑以下コンver.) * @author Keitaro Naruse * @date 2023-12-02 * @copyright MIT License * @details https://yukicoder.me/problems/no/2562 * */ // # Solution #include #include #include #include template < class T > std::ostream& operator<<( std::ostream& os, const std::vector< T >& v ) { for( auto it = v.begin( ); it != v.end( ); it++ ) { os << *it << ( it == --v.end( ) ? "" : " " ); } return os; } int main( ) { // Read T = [ 1, 10^4 ] int T; std::cin >> T; // Multiple queries for( int t = 0; t < T; t++ ) { // Read M = [ 1, 10^9 ] long long M; std::cin >> M; // Read di = [ 1, 9 ] std::vector< int > d( 10 ); for( int i = 1; i <= 9; i++ ) { std::cin >> d.at( i ); } // Main::Preprocess std::string digits; for( int i = 1; i <= 9; i++ ) { for( char j = 0; j < d.at( i ); j++ ) { digits.push_back( '0' + i ); } } long long answer = 0LL; do { long long val = std::stoll( digits ); if( val % M == 0LL ) { answer = val; break; } } while( std::next_permutation( digits.begin( ), digits.end( ) ) ); // Main::Find a solution // Main::Output a solution std::cout << answer << std::endl; } // Finalize return 0; }