/** * @file 2558.cpp * @brief yukicoder problem 2558 * @author Keitaro Naruse * @date 2023-12-02 * @copyright MIT License * @details https://yukicoder.me/problems/no/2558 * */ // # Solution #include int main( ) { // Read A, B = [ 1, 3*10^3 ], a = [ 0, A ), b = [ 0, B ) int A, B, a, b; std::cin >> A >> B >> a >> b; // Main::Preprocess // Main::Find a solution int answer = 0; for( int x = 0; x < A * B; x++ ) { if( x % A == a && x % B == b ) { answer = x; break; } } // Main::Output a solution std::cout << answer << std::endl; // Finalize return 0; }